I’m trying to pass the value of a text box to a action method through jquery ajax method. The action method will return a bool value, based on which I need to show a message in my view. I’m trying this:
<script type="text/javascript">
$(document).ready(function () {
$('#UserName').blur(function () {
var name = this.value;
$.get(@Url.Action("CheckUserName"),{UserName:name},function(data,status){
if(data==true)
{
}
else
{
}
}););
})
});
</script>
Now the problem is, only the if statement is executing! I have checked my action method, its returning true & false accordingly. I need to know what the callback function’s parameter “data” is supposed to do? Will it hold the data returned from the action method?
You’re missing quotes around url.
Remember, that you need to render a proper javascript, and strings in js need to be enclosed with quotes.