Answer the question
In order to leave comments, you need to log in
How to process JSON data which is actually XML?
I'm doing a cross-site request for geodata by IP. I suffered for a long time, no ways to resolve such a request with XML data worked. It only works if I do like this:
$.get('http://ipgeobase.ru:7020/geo?ip=89.107.39.118', function(data) {
//тут как-то я получаю myregion из ответа
}, 'jsonp');
<?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>Ессентуки</city><region>Ставропольский край</region><district>Северо-Кавказский федеральный округ</district><lat>44.049809</lat><lng>42.857239</lng></ip>
</ip-answer>
Answer the question
In order to leave comments, you need to log in
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 ;
}
For jsonp to work, server-side support is needed - the returned result must be a valid javascript code, usually a function call with data as an argument, the function name is passed to the server as a get parameter. Whether the data will be json or xml is essentially not important - in this case, the service simply does not support this interaction option - choose another one, for example:
http://freegeoip.net/json/89.107.39.118?callback=callback
http://ipgeobase.ru:7020/geo?ip=89.107.39.118&json=1 - here is the output in json format
there are three options:
1) make a “proxy” on the backend. Those. use ajax to pull your backend, which in turn will pull ipgeobase
2) bother with the old ways of "ajax" (iframe, etc.)
3) try to contact ipgeobase and ask them to return the correct Access-Control-Allow-Origin header
replace 'jsonp' with 'xml'?
in general, see mana by $.get. I don't know what library you have.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question