0

I have written the following code to read a JSON document from an external URL. This worked fine when the URL was the following:

 http://localhost/EWSimpleWebAPI/odata/Users?

But NOT when I modified the URL as the following:

http://localhost/EWSimpleWebAPI/odata/Users?$filter=USER_NAME%20eq%20%27corpnet\anuwlk%27&$select=PROFILE

Javascript

var xmlhttp = new XMLHttpRequest();

var url = "http://localhost/EWSimpleWebAPI/odata/Users?$filter=USER_NAME%20eq%20%27corpnet\anuwlk%27&$select=PROFILE";

xmlhttp.open("GET", url, true);

xmlhttp.onreadystatechange=function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
    myFunction(xmlhttp.responseText);
    errorAlert("Status OKAY");
  } else{
    errorAlert("Status Not OKAY")
  }
}

xmlhttp.send();

I'm retrieving the JSON Document thru a Web API using OData. OData accepts parameters in the URL and it worked fine in POSTMAN. I'm developing a Google Chrome extension and I'm not sure if it supports this URL with Parameters.

abraham
  • 46,583
  • 10
  • 100
  • 152
wishman
  • 774
  • 4
  • 14
  • 31

1 Answers1

3

It would be best to use some function ( encodeURIComponent(str) and encodeURI(str) come to mind) to encode the parameters correctly.

As wOxxOm commented, your issue seems that one of the parameter has an unescaped character \.

JMCampos
  • 636
  • 1
  • 9
  • 21
  • 1
    [See this answer for clearness](http://stackoverflow.com/questions/75980/best-practice-escape-or-encodeuri-encodeuricomponent) – JMCampos Aug 03 '15 at 10:57