How to handle JSON data, which are actually XML

Doing intersite request GEODATA for IP. Long suffered, no way to resolve such a request with XML data is not earned. Only works if I do this:

$.get('http://ipgeobase.ru:7020/geo?ip=89.107.39.118', function(data) { //here somehow I get myregion from the response }, 'jsonp');

The server's response in XML format:
<?xml version="1.0" encoding="windows-1251"?> <ip-answer> <ip value="89.107.39.118"><inetnum>89.107.32.0 - 89.107.39.255</inetnum><country>RU</country><city>Essentuki</city><region>Stavropol Krai</region><district>North Caucasian Federal district</district><lat>44.049809</lat><lng>42.857239</lng></ip> </ip-answer>

What browser answers "Uncaught SyntaxError: Unexpected token < "as I understand it, is not able to handle the angle bracket. I would be able to extract from this response the desired data. But how to get the browser to accept them without error? Maybe you can process the response from the built-in parsing?
October 3rd 19 at 02:28
6 answers
October 3rd 19 at 02:30
Solution
I don't understand something, or
 function httpGet(theUrl)
    {
    var xmlHttp = null;
 
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", theUrl, false );
xmlHttp.send( null );
    return xmlHttp.responseText;
    }


and parsim responseText,
not?
Cool! Works :) - Catalina_Jast commented on October 3rd 19 at 02:33
October 3rd 19 at 02:32
To jsonp earned, we need support from server, the result returned should be walindi javascript code, usually a function call with the data as argument, the function name is passed to the server as a get parameter. Whether the data is json or xml in fact does not matter — in this case a service does not support the option of interaction — select another, for example:
http://freegeoip.net/json/89.107.39.118?callback=callback
Okay, thanks a lot! - Catalina_Jast commented on October 3rd 19 at 02:35
Service all good, the only data I would like to get in Russian. - Catalina_Jast commented on October 3rd 19 at 02:38
October 3rd 19 at 02:34
http://ipgeobase.ru:7020/geo?ip=89.107.39.118&json=1 — here's the results in json format
c jsonp still will not work because jsonp requires that the response be circulated in the call of Kabaka. - Catalina_Jast commented on October 3rd 19 at 02:37
Oh thank you! On their website, I such documentation is not found!) - Catalina_Jast commented on October 3rd 19 at 02:40
I do), brute force, learned)) - Catalina_Jast commented on October 3rd 19 at 02:43
October 3rd 19 at 02:36
there are three options:
1) to do on the backend, "proxy". Ie Ajax to pull your backend, and that, in turn, pulls ipgeobase
2) to bother with the old ways, Ajax (iframe, etc.)
3) try to ccontact with ipgeobase and ask them to give the correct header Access-Control-Allow-Origin
October 3rd 19 at 02:38
replace 'jsonp' and 'xml'?

in General, look at the mana $.get. Don't know what you have for the library.
if you use xml, an error occurs "is not allowed by Access-Control-Allow-Origin" - Catalina_Jast commented on October 3rd 19 at 02:41
crossdomain — only jsonp - Catalina_Jast commented on October 3rd 19 at 02:44
October 3rd 19 at 02:40
Why don't you specify a JSONP format instead of XML?
Because then the error occurs "is not allowed by Access-Control-Allow-Origin"
Here it is written read more habrahabr.ru/post/67961/
And just the guys discuss the possibility of treatment. How's that not saying! - Catalina_Jast commented on October 3rd 19 at 02:43

Find more questions by tags JSONAJAXJavaScript