Cross Domain Domain Ajax Call Using JQuery WCF REST Starter Kit Preview 2

I created and hosted my WCF API using the WCF REST Starter Kit preview2. Which supports the format of the format Dynamic Response and Request (XML and JSON). Everything works fine if I use the service in the same domain through jQuery, Microsoft.Http.

My cs code is as follows:

private void GetData()
    {
        string url = string.Format("http://myhost/Services/UserService.svc/people/");
        HttpClient client = new HttpClient();
        HttpResponseMessage responseMessage = client.Get(url);
        responseMessage.EnsureStatusIsSuccessful();
        using (responseMessage)
        {
            string res = responseMessage.Content.ReadAsString();
            Response.Write(res);
        }
    }

now when I try to use my service using jQuery from another domain, the Response is sent in IE8, but in Mozilla and Chrome I get a null response My jquery code looks like this:

 function loadData() {
    var path = "http://myhost/Services/UserService.svc/people/";       
    $.ajax({
        type: "GET",
        url: path,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        success: function(response) {               
            if (response != null) {
                displayData(response);                   
            }
        }
    });
}

I am also trying to set the data type: calling "jsonp" and .getJson ().

+3
source share
1

ProxyHandler . ( ), REST ( ).

HtppHandler (Proxy), .

HTTP ASP.NET Visual #.NET

HttpHandler -

0

Source: https://habr.com/ru/post/1765256/


All Articles