2

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.
Shivam Aggarwal
  • 795
  • 1
  • 11
  • 30
  • Does it require any type of authentication to make the request? I only ask because that looks like a redirect to a guest page, with the original url encoded. – Reinstate Monica Cellio Mar 09 '18 at 08:48
  • No,it does not require any authentication at all.Plus 'http://localhost/web/guest/' this is the default local url,which is somehow appended to the local url – Shivam Aggarwal Mar 09 '18 at 08:56
  • The only thing I can suggest is to create the url before the ajax call and log it to the console to make sure it's exactly what you expect. the jQuery Ajax method doesn't just change urls on the fly, unless you've explicitly written code to do so. – Reinstate Monica Cellio Mar 09 '18 at 09:00
  • Yes I did exactly the same,and it displays the correct url,but then the ajax call is made to this weird url – Shivam Aggarwal Mar 09 '18 at 09:05
  • 1
    Out of curiosity, if you build the url as a string before the ajax call and then use that variable as the url parameter, does it do the same thing? I only ask because it's currently delimiting the url by wrapping _sbUrl with double quotes (%22 = ") – Reinstate Monica Cellio Mar 09 '18 at 09:36
  • Nice catch!So I had already tried var url = encodeURI(_sbUrl+"gates/1.0/sweeps/getVehicleDetails/"+request.data.regn_no); and passed this variable to url,but with the same results. Anything that need to make it to string or may be with single or double quotes? – Shivam Aggarwal Mar 09 '18 at 09:52
  • Why are you encoding a Url? Just use regular string concatenation and you've got your Url. – Reinstate Monica Cellio Mar 09 '18 at 09:56
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/166521/discussion-between-shivam-aggarwal-and-archer). – Shivam Aggarwal Mar 09 '18 at 09:57
  • @Archer Thanks for %22 pointer,it was due to the enclosing quotes – Shivam Aggarwal Mar 09 '18 at 12:55
  • That was the most obvious culprit, hence my suggestion. Glad you got it sorted :) – Reinstate Monica Cellio Mar 09 '18 at 12:56

1 Answers1

1

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.

Shivam Aggarwal
  • 795
  • 1
  • 11
  • 30