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 aJSONP
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
3 Answers
Reset to default 5You 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