Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs $http "XML Parsing Error: no element found Location" error when expecting JSON results on GET

When I submit an angularjs $http GET call I receive an XML parsing error.

The $http call code snippet is:

$http({
    method: 'GET',
    url: "myapp/api/items" + itemId
 });

The error is:

XML Parsing Error: no element found Location: moz-nullprincipal:{f191853f-5581-b049-b83f-5f4b69211adb} Line Number 1, Column 1:

The data being returned is JSON. If I put the URL in a browser then the request is submitted and the response data comes back successfully in the browser.

I tried adding responseType: 'json' (and responseType: 'application/json') to the $http call with no success. (I referenced the Usage section in angularjs http doc to determine how to configure the call.)

Is there a way I can force the response data to be recognize as json to avoid that error?

like image 894
whyceewhite Avatar asked Jun 18 '14 20:06

whyceewhite


Video Answer


2 Answers

If you are using Mozilla Firefox, install firebug and try to inspect the http GET in the Net panel or in the Console panel.

In the headers tab you can check the Content-Types being sent and received. Maybe the problem is in the server-side response's content-type.

like image 93
Roberto Linares Avatar answered Sep 18 '22 12:09

Roberto Linares


May be you are running your app in file:///, since this is AJAX request this can be happen. If you have installed nodejs, you can install a server and see console log.

To install a server on nodejs

npm install -g http-server

And go to(cd into) your project directory and:

http-server -o. -o

Now see the browser console.

like image 29
Blasanka Avatar answered Sep 21 '22 12:09

Blasanka