0

While calling MVC webservice from my html page it was always going to error; please help me

$.ajax({ type: "GET", url: url, contentType: "application/json; charset=utf-8", crossDomain: true, dataType: "json", success: function (msg) { alert(Response.ErrorMessage ) }, error: function (e, status) { alert(e + " Fail " + status) } }); 
4
  • 1
    have you tried dataType : "jsonp" ? which error message you get? Commented Apr 3, 2014 at 14:25
  • you don't need crossDomain: true, or contentType: "application/json; charset=utf-8", Commented Apr 3, 2014 at 14:33
  • Start by opening your javascript debugging console and looking for error messages. Next, still within your javascript debugging console, look at the network requests that took place to see if your server returned what you expected it to. Commented Apr 3, 2014 at 14:34
  • yes i tried Jsonp and callback also Commented Apr 4, 2014 at 5:07

1 Answer 1

2

You have to setup CORS (http://www.html5rocks.com/en/tutorials/cors/) or use JSONP. If you decide to use JSONP then you have to send proper callback function name with JSON data.

Sign up to request clarification or add additional context in comments.

2 Comments

To complement this answer: If you want to use JSONP, please also have a look at the possible security concerns of it...
Yea, you should use CORS if it is viable option for you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.