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";}
}
You really should get known with FireBug
Your JavaScript looks extra wrong 🙂
First of all, inline javascripts should be formatted like this:
Than check out the jQuery.post() docs and overall javascript syntax…