Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-14-2009, 01:53 AM   PM User | #1
codegreen
New Coder

 
Join Date: Dec 2006
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
codegreen is an unknown quantity at this point
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.
codegreen is offline   Reply With Quote
Old 02-14-2009, 10:17 AM   PM User | #2
Iszak
Regular Coder

 
Iszak's Avatar
 
Join Date: Jun 2007
Location: Perth, Western Australia
Posts: 332
Thanks: 2
Thanked 58 Times in 57 Posts
Iszak is an unknown quantity at this point
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.
Iszak is offline   Reply With Quote
Users who have thanked Iszak for this post:
codegreen (02-15-2009)
Old 02-15-2009, 06:13 AM   PM User | #3
codegreen
New Coder

 
Join Date: Dec 2006
Posts: 18
Thanks: 2
Thanked 0 Times in 0 Posts
codegreen is an unknown quantity at this point
Thanks...that's exactly what I needed!
codegreen is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:03 PM.


Advertisement
Log in to turn off these ads.