简体   繁体   中英

Cross domain Ajax Call

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)
    }
}); 

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM