Click here to Skip to main content
16,020,669 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
We have proxy implemented in our office, I need to make webservice call using jQuery AJAX.

If we skip proxy, the web method gets called without any errors.
But the moment we enable proxy, we get "NetworkError" no more details available regarding this error.

We cannot disable proxy forever, now we want to call this webservice using jQuery AJAX.
Please help me resolve the issue.

JavaScript
var surl = "http://www.mydomain.com/MyJSONService/Service.asmx/HelloWorld";
$.ajax({
    type: 'GET',
    url: surl,
    crossDomain: true,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    xhrFields: {
         withCredentials: true
    },
    success: function(data, statusCode, xhr) {
        alert(data.d);
    },
    error: function(xhr, status, error) { 
        alert('Error !!'); 
    },
    async: false,
    cache: false
});
Posted
Comments
Kornfeld Eliyahu Peter 27-Apr-14 9:29am    
When proxy is on, can you browse your site?
did you heard about jQuery.ajaxPrefilter()?
Abdul Muqeet Ahmed 28-Apr-14 2:55am    
Yes when proxy is on I can browse the site.<br>
I have set jQuery.ajaxPrefilter(), and set async to true.<br>
Now I get a new error called "error" with status code "0" and status text "error"

1 solution

Please try is as below.

Note: This is just a sample.Adjust it according to your app.

$.ajaxPrefilter( function( options ) {
  if ( options.crossDomain ) {
    var newData = {};
    // Copy the options.data object to the newData.data property.
    // We need to do this because javascript doesn't deep-copy variables by default.
    newData.data = $.extend({}, options.data);
    newData.url = options.url;

    // Reset the options object - we'll re-populate in the following lines.
    options = {};

    // Set the proxy URL
    options.url = "http://mydomain.com/proxy";
    options.data = $.param(newData);
    options.crossDomain = false;
  }
});


For more info : Pass Through Cross Domain Proxies with jQuery

jQuery.ajaxPrefilter()
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900