jQuery
New Wave Javascript
discuss » AJAX with post: how to build name value pair as in a post request submitted by form?
Posted: Fri Mar 3 11:00:34 EST 2006
From: John Resig <
jeresig at gmail.com
>
Hi Klaus,
Your example is a little bit trickier than average, but it's
definitely possible to work around.
Looking at this block of code:
$("input[@type='text']").blur(function() {
query = { this.name: this.value };
$("em", this.parentNode).load("some_url", query);
}
and this line:
query = { this.name: this.value };
The problem is that in Javascript you can't set dynamic 'key' values
in an associative array, using that notation. To work around this
you'll have to do:
var query = {};
query[this.name] = this.value;
I hope that helps!
--John
On 3/3/06, Klaus Hartl <
office at stilbuero.de> wrote:
>
Hi there,
>
>
how can I transmit a post request with the AJAX module that looks
>
exactly like a post request submitted by a form?
>
>
If my field looks like this:
>
>
<input type="text" name="foo" value="bar" />
>
>
>
the request send via XMLHttpRequest should look like:
>
>
foo=bar
>
>
>
The following fails because of an invalid property id:
>
>
$("input[@type='text']").blur(function() {
>
query = { this.name: this.value };
>
$("em", this.parentNode).load("some_url", query);
>
}
>
>
and I don't want to do this:
>
>
>
$("input[@type='text']").blur(function() {
>
query = { field: this.name, validate: this.value };
>
...
>
}
>
>
>
Thanks in advance for some help!
>
>
Klaus
>
>
_______________________________________________
>
jQuery mailing list
>
discuss at jquery.com
>
http://jquery.com/discuss/
>
--
John Resig
http://ejohn.org/jeresig at gmail.com