Is this the only way to pass a parameter for Cakephp to work with JQuery Ajax

Posted by kwokwai on Stack Overflow See other posts from Stack Overflow or by kwokwai
Published on 2010-05-30T20:42:43Z Indexed on 2010/05/30 21:02 UTC
Read the original article Hit count: 187

Filed under:

Hi all,

I was doing some self-learning on how to pass data from JQuery Ajax to a particular URL in CakePHP:
I have tested three sets of codes that the first one was working well, but the rest failed to work, which makes me so confused.
Could some experts here tell why the second and the third sets of codes failed to pass any data?

Set 1:

<input type=text name="data[User][name]" id="data[User][name]" size="36" maxlength="36"/>
var usr = $("#data\\[User\\]\\[name\\]").val();
$.post(
"http://www.washington.byethost18.com/site1/toavail/"+usr,
function(msg){alert(msg);}
);

Set 2:

<input type=text name="data[User][name]" id="data[User][name]" size="36" maxlength="36"/>
var usr = $("#data\\[User\\]\\[name\\]").val();
$.post(
"http://www.washington.byethost18.com/site1/toavail/",
 {queryString: ""+usr+""},
 function(msg){alert(msg);}
 );

Set 3:

<input type=text name="data[User][name]" id="data[User][name]" size="36" maxlength="36"/>
var usr = $("#data\\[User\\]\\[name\\]").val();
$.post(
"http://www.washington.byethost18.com/site1/toavail/",
 usr,
 function(msg){alert(msg);}
);

© Stack Overflow or respective owner

Related posts about cakephp