Search code examples
jqueryajaxinternet-explorer-10url-encodingliferay-7

Local url being concatenated to absolute url using jquery ajax


We are using jquery ajax to make a service get call:

$.ajax({
  url: _sbUrl + "gates/1.0/sweeps/getVehicleDetails/" + request.data.regn_no,
  method: "GET",
  success: function(response) {
    if (200 === response.statusCode) {
      if (typeof callback === 'function') callback(response);
    } else if (typeof callback === 'function') callback({});
  },
  error: function(response) {
    if (typeof callback === 'function') callback({});
  }
});

Here _sbUrl is used http://192.32.45.34:9090/. When the call is made,the url is updated to this

http://localhost/web/guest/%22http://192.32.45.34:9090/%22gates/1.0/sweeps/getVehicleDetails/DE3SA2323

This is only happening on IE10 and below versions of IE,while working fine on all other browsers. I have tried:

  1. Encoding URL
  2. Added crossdomain = true But none of them worked.Is this a known bug for jQuery?If yes,do we have a workaround for the same.

Solution

  • As per recommendation from @Archer,the issue was with _sbUrl. The Url was being fetched as string from properties file and for IE10,it included the quotes as well. So http://192.32.45.34:9090/ was being fetched as "http://192.32.45.34:9090/"

    _sbUrl = _sbUrl.replace(/\\\//g, "/");
    

    The deduction from @Archer was due to the point,that %22http://192.32.45.34:9090/%22 had %22(equivalent to ") as prefix and suffix.