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.

2
  • 2
    Your url has an unescaped control character \a, should be \\a. I've voted to close the question due to the problem being a typo. Commented Aug 3, 2015 at 10:41
  • Thanks, your comment solved my question Commented Aug 3, 2015 at 10:51

1 Answer 1

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 \.

Sign up to request clarification or add additional context in comments.

1 Comment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.