www.webdeveloper.com
Results 1 to 4 of 4

Thread: How to send value to a PHP page using Jquery & AJax

  1. #1
    Join Date
    Apr 2014
    Posts
    38

    How to send value to a PHP page using Jquery & AJax

    The input I'm trying to get the value of is:
    Code:
    <input type='hidden' name='hidden_image' class='hidden_image'>
    This is the Jquery I have so far:
    Code:
      var image_value = $('.hidden_image').serialize();
          $.ajax({ type:'GET', url: 'liked_button.php', data:{"img":image} });
    And this is the code on my liked_button.php to get the value of the hidden_image field:
    Code:
    $liked_img_loc = $_GET['img'];
    Like I said, I'm trying to send the value of the hidden_input to liked_button.php, then use "$_GET" on liked_button.php to get the value of that hidden_image field. What am I doing wrong?

  2. #2
    Join Date
    Jun 2014
    Posts
    8
    The issue:
    You are assigning the value of ".hidden_image" to ' var image_value ' however in the ajax data parameter you are passing it variable 'image'.

    Quick Answer:

    Looks like this:
    Code:
    var image_value = $('.hidden_image').serialize();
          $.ajax({ type:'GET', url: 'liked_button.php', data:{"img":image} });
    Should be this:
    Code:
    var image_value = $('.hidden_image').serialize();
          $.ajax({ type:'GET', url: 'liked_button.php', data:{"img":image_value} });

  3. #3
    Join Date
    Jun 2014
    Posts
    8
    Continuation: I also noticed you are using quotes for "img", you needn't, you can get away with it being this:

    Code:
    var image_value = $('.hidden_image').serialize();
          $.ajax({ type:'GET', url: 'liked_button.php', data:{img:image_value} });

  4. #4
    Join Date
    Jun 2014
    Posts
    8
    Continuation 2:

    BAH! I just noticed that it's also worth knowing that It's probably more secure to use POST:

    Code:
    var image_value = $('.hidden_image').serialize();
          $.ajax({ type:'POST', url: 'liked_button.php', data:{img:image_value} });
    This just access with $_POST['img']

    ( Sorry about all the posts, I would edit these but I can't yet )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles