Is this the only way to pass a parameter for Cakephp to work with JQuery Ajax
- by kwokwai
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);}
);