I have a REST API service http://services.mycompany.com/Employees/ and browse this service results XML as shown above. I want to read via Ajax/Json call. I added a simple script
The output alert always throw the following result:
Result: parsererror : SyntaxError: Unexpected token < in JSON at position 0 : 200 :OK
Will you please help troubleshooting? Do I have to convert xml to JSON? I verified in Fiddler debugging and I see that the 'url' has the complete xml value however it never produce result and always display the parseerror as stated.
All I need is total employees returned from the web service count. In the above case, it should alert me as "2". Any other easiest way to get the result would also work but it should work in .aspx page.
The response is xml, not json. As .getJSON() sends the accept json header, it expects a Json result. , it appears you rest api does not support json. So you need to Use $.get(). the result of the $.get() will be an xml dom. See jquery support of xml to access
your data.
You're receiving HTML (or XML) back from the server, but the dataType: json is telling
jQuery to parse as JSON. Check the "Network" tab in Chrome dev tools to see contents of the server's response.
I would suggest that you add to your logging. Looking at the actual xhr (XMLHttpRequest) properties to learn more about the response. Try adding console.warn(xhr.responseText) and you will most likely see the HTML that is
being received.
None
0 Points
11 Posts
Result: - parsererror : -SyntaxError: Unexpected token < in JSON at position 0:-200 :-OK
Aug 21, 2020 07:36 PM|Swatisri|LINK
I have a REST API service http://services.mycompany.com/Employees/ and browse this service results XML as shown above. I want to read via Ajax/Json call. I added a simple script
The output alert always throw the following result:
Result: parsererror : SyntaxError: Unexpected token < in JSON at position 0 : 200 :OK
Will you please help troubleshooting? Do I have to convert xml to JSON? I verified in Fiddler debugging and I see that the 'url' has the complete xml value however it never produce result and always display the parseerror as stated.
All I need is total employees returned from the web service count. In the above case, it should alert me as "2". Any other easiest way to get the result would also work but it should work in .aspx page.
All-Star
58474 Points
15790 Posts
Re: Result: - parsererror : -SyntaxError: Unexpected token < in JSON at position 0:-200 :-OK
Aug 22, 2020 03:06 PM|bruce (sqlwork.com)|LINK
The response is xml, not json. As .getJSON() sends the accept json header, it expects a Json result. , it appears you rest api does not support json. So you need to Use $.get(). the result of the $.get() will be an xml dom. See jquery support of xml to access your data.
None
0 Points
14 Posts
Re: Result: - parsererror : -SyntaxError: Unexpected token < in JSON at position 0:-200 :-OK
Aug 24, 2020 06:12 AM|EvanChatter|LINK
You're receiving HTML (or XML) back from the server, but the
dataType: json
is telling jQuery to parse as JSON. Check the "Network" tab in Chrome dev tools to see contents of the server's response.I would suggest that you add to your logging. Looking at the actual
xhr
(XMLHttpRequest) properties to learn more about the response. Try addingconsole.warn(xhr.responseText)
and you will most likely see the HTML that is being received.