Reputation: 3321
I am learning how to use JQuery to help check data availability.
I have written a function in a Controller for checking data input, and the URL is like this: http://www.mywebsite.com/controllers/action/avariable
But the returned data was blank.
<script language="javascript">
$(document).ready(function(){
$(document).change(function(){
var usr = $("#data\\[User\\]\\[name\\]").val();
$.post{"http://www.mywebsite.com/controllers/action/",
usr,
function(msg){alert(msg);}
}
});
});
</script>
<div id="username">
<input type=text name="data[User][name]" id="data[User][name]">
</div>
Here is the code of the Action:
function action($data=null){
$this->autoRender = false;
$result2=$this->__avail($data);
if($result2==1)
{return "OK";}
else
{return "NOT";}
}
Upvotes: 0
Views: 111
Reputation: 4617
You really should get known with FireBug
Your JavaScript looks extra wrong :)
First of all, inline javascripts should be formatted like this:
<script type="text/javascript">
Than check out the jQuery.post() docs and overall javascript syntax...
Upvotes: 2