jsonp cross domain only working in IE

Posted by iboeno on Stack Overflow See other posts from Stack Overflow or by iboeno
Published on 2010-04-28T15:23:53Z Indexed on 2010/04/30 8:57 UTC
Read the original article Hit count: 309

Filed under:
|
|
|

EDIT: At first I thought it wasn't working cross domain at all, now I realize it only works in IE

I'm using jQuery to call a web service (ASP.NET .axmx), and trying to us jsonp so that I can call it across different sites. Right now it is working ONLY in IE, but not in Firefox, Chrome, Safari. Also, in IE, a dialog pops up warning "This page is accessing information that is not under its control..." Any ideas?

Here is the code:

$.ajax({
    type: "POST",
    url: "http://test/TestService.asmx/HelloWorld?jsonp=?",
    dataType: "jsonp",
    success: function(data) {
        alert(data.prop1);
    },
    error: function(XMLHttpRequest, textStatus, errorThrown) {
        alert(XMLHttpRequest.status + " " + textStatus + " " + errorThrown);
    }
}); 

And the server code is:

[ScriptService]
public class TestService : System.Web.Services.WebService{
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public void HelloWorld() {
        string jsoncallback = HttpContext.Current.Request["jsonp"];
        var response = string.Format("{0}({1});", jsoncallback, @"{'prop1' : '" + DateTime.Now.ToString() + "'}");
        HttpContext.Current.Response.Write(response);
    }
}

© Stack Overflow or respective owner

Related posts about jsonp

Related posts about jQuery