Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts

    jQuery: Posting Data in the load functions

    Hi,
    I'm using the jQuery load function to make an AJAX call. I know that paired key : value variables placed after the url are POSTED but I need to be able to pass these values in dynamically depending on the function that's calling load.

    so for example I need:

    Code:
    var post_content;
    
    ....
    
    [post_content is set dynamically]
    
    $('page_content').load(url, post_content, function() {..do stuff...});

    In this case post_content is a global var whose value changes depending on the data I need to pass to the load function.

    I've tried doing stuff like this:

    Code:
    post_content = "{'id' : '1', 'answer' : 'yes'}";
    but instead of posting that data...it just adds it to the query string and does a GET.

    Is there any way to dynamically set this post_content variable and have is passed so that it will POST as if I've done this:

    Code:
    $('page_content').load(url, {'id':'1', 'answer':'yes'}, function() {..do stuff...});
    Because in that case the data gets POSTED.

    Thank you in advance.

  • #2
    Regular Coder Iszak's Avatar
    Join Date
    Jun 2007
    Location
    Perth, Western Australia
    Posts
    332
    Thanks
    2
    Thanked 58 Times in 57 Posts
    Why not just use the post function instead of the load, and that will ensure it'll be a POST. Also on your code you're setting post_content as a string and not as JSON? Because it's in speech marks.. and not simply in {} so maybe remove that and see if that makes any difference before switching to the post function.

  • Users who have thanked Iszak for this post:

    codegreen (02-15-2009)

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    18
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks...that's exactly what I needed!


  •  

    Posting Permissions

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