最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Cross domain Post method ajax call using jQuery with XML response - Stack Overflow

programmeradmin5浏览0评论

I want to send a ajax request using post method with the XML as a response text, Is it possible, If it is possible please let me know the possible way for it.

For Ex

url : ".asmx/ConversionRate"
data : {FromCurrency:"INR",ToCurrency:"AUD"}
method : GET or POST

.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD

I need the response of this URL using ajax.

I want to send a ajax request using post method with the XML as a response text, Is it possible, If it is possible please let me know the possible way for it.

For Ex

url : "http://www.webservicex/CurrencyConvertor.asmx/ConversionRate"
data : {FromCurrency:"INR",ToCurrency:"AUD"}
method : GET or POST

http://www.webservicex/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD

I need the response of this URL using ajax.

Share Improve this question edited May 19, 2022 at 17:28 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 28, 2012 at 7:04 SanthanamSanthanam 3484 silver badges15 bronze badges 6
  • If they support JSONP, you can add that switch. You have to learn how to do it, though. This tutorial isn't too bad. – Jared Farrish Commented Jun 28, 2012 at 7:07
  • Actually, you'd probably want CORS if that site doesn't have a JSONP feed. Of course, the browser has to support it too. – Jared Farrish Commented Jun 28, 2012 at 7:10
  • Without JSONP cant we render the content using some other methods?? – Santhanam Commented Jun 28, 2012 at 7:17
  • CORS. Or a server-routed proxy using cURL or something. It's a same-origin issue; there's only a few ways around it. – Jared Farrish Commented Jun 28, 2012 at 7:25
  • can also use a 3rd party proxy like Yahoo YQL. Can get a jsonp url set up in minutes in YQL console – charlietfl Commented Jun 28, 2012 at 7:47
 |  Show 1 more ment

3 Answers 3

Reset to default 5

You can use YQL,

var url = 'http://www.webservicex/CurrencyConvertor.asmx/ConversionRate?FromCurrency=INR&ToCurrency=AUD'; // website you want to scrape
var yql = 'http://query.yahooapis./v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=json&callback=?';  
$.getJSON(yql,function(data){  
    if(data.query.results){
        var result = data.query.results.double.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
        alert(result);
    }
});

You can write your own script on server on the same domain that does request to the webservicex and returns data in any format that you want.

So, ajax request -> your server (on the same domain) -> webservicex

It seems that server does not support CORS. Then you won't be able to do this with an ajax call due to the same origin policy

发布评论

评论列表(0)

  1. 暂无评论