开发者

Cross domain request on Google Weather XML

开发者 https://www.devze.com 2023-04-12 21:31 出处:网络
I want to grab the google weather xml, using ajax call but I \'m getting the following error: 405 Method not allowed

I want to grab the google weather xml, using ajax call but I 'm getting the following error:

405 Method not allowed

Its always been a trouble to make a cross domain call, I know we can do it using jsonp but the api is returning xml.

var weather= function(){

url = 'http://ww开发者_JS百科w.google.com/ig/api?weather=karachi';
var gurl = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=" +escape( url);


/*SERVER CALL FOR CROSS DOMAIN*/
//ServerCallRAW('http://www.google.com/crossdomain.xml', function(_dataCD){

    //console.log(_dataCD);
    ServerCallXML(url, function(_dataAPI){

        console.log(_dataAPI);
    //});
});

};


function ServerCallXML(_url,callback) {
    $.ajax
    ({
        type: "GET",
        url: _url,
        dataType: 'xml',
        //contentType: "application/json; charset=utf-8",
        contentType: "text/xml; charset=iso-8859-1",
        async: false,
        //data: {'json':'{"username":"' + username + '", "password":"' + password + '"}'},
        success: function (result) {
            callback(result);
        }
    });
};

thanks


You can create a local proxy on your server to avoid the cross-domain request. That is you essentially create a page that performs a cURL(php) or HttpRequest(c# etc) then renders the contents of the cURL/HttpRequest as it's response. Unlike javascript (client side code) servers are not typically restricted to making only same-domain requests.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号