0

I have a form, I want to check the username is availability. I that I have html textbox, in Onclcik I'm calling java script function. The script has to call the Action methods in controller. Based upon the username availability it has to return either 1 or 0. I have tried Json. But its is showing "Microsoft JScript runtime error: '$' is undefined". Can anyone help me in this.

1
  • add this below the title of the document <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js></script>" Commented Jun 8, 2011 at 12:08

2 Answers 2

2

If you get that message it means you're trying to use jQuery but you haven't included the library. You can use Google's CDN. I guess you've used Ajax to call. Something like this:

$.ajax({
    type: 'POST',
        url: '<%=Url.Action("Your Action", "Your Controller")%>',
    data: { userName: $('#UserName').val(), password: $('#Password').val() },
        dataType: 'json',
        complete: function(XMLHttpRequest, textStatus) {
    // User your JSON response.
    }
});

If you're using a POST you have to decorate your action with the attribute [HttpPost] and remember to specify JsonRequestBehavior.DenyGet when you return your JSON object:

[HttpPost]
public JsonResult CheckUserName(string userName, string password)
{
    // notification: your object
    return (Json(notification, JsonRequestBehavior.DenyGet));
}
Sign up to request clarification or add additional context in comments.

Comments

2

If you are using Jquery (the $ sign), then that means that you need a script reference to jquery implementation before your javascript code that calls JSON.

script type="text/javascript" src="jquery.js"></script>

Where jquery.js is the latest version of the jquery javascript file

2 Comments

So can u tell me which script I need to reference. In MVC project I have nearly 6 jquery scripts
Cool, thanks man, just for that, I'll vote you up too given that you've made more effort :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.