这是否适用于xml解析,就像我使用json进行的解析一样,但它没有显示来自web服务的任何响应。这是webservice的状态 http/1.1 405方法不允许113 is
$j.ajax({
type: "GET",
async: false,
url: "Service1.asmx",
dataType: 'XML',
//contentType:'application/json',
success: function (data) {
$j.each(data, function (index, element) {
alert("Successful here: " + element);
//$j('#json').append("<li'>"+element+"</li>");
});
}
}).done(function (data) {
console.log(data);
alert("XML Data: " + data);
});发布于 2013-05-30 07:51:27
在ajax的url参数中使用您的方法名,如:url: "Service.asmx/ConversionRate"
如果您正在调用一个位于不同域中的web服务,例如:您正在编写ajax函数的.js文件是在www.abc.com中,并且是在www.xyz.com (即跨域调用)中调用web服务,那么您需要使用如下所示的服务器路由代理,或者浏览器不允许使用jsonp作为跨域调用。
var url = 'http://www.webservicex.net/Service1.asmx/ConversionRate;
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=json&callback=?';
$j.ajax({
type: "GET",
async: false,
url: yql,
dataType: 'XML',
//contentType:'application/json',
success: function (data) {
if(data.query.results){
var result = data.query.results.double.content.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
$j.each(result, function (index, element) {
alert("Successful here: " + element);
//$j('#json').append("<li'>"+element+"</li>");
});
}
}
});使用success或done函数,因为它们都具有相同的用途。
如果您正在使用来自同一域的服务,则不需要上述服务器路由代理。然后代码如下所示。
$j.ajax({
type: "GET",
async: false,
url: "Service1.asmx/GetConversion",
dataType: 'XML',
//contentType:'application/json',
success: function (data) {
$j.each(data, function (index, element) {
alert("Successful here: " + element);
//$j('#json').append("<li'>"+element+"</li>");
});
}
});https://stackoverflow.com/questions/16828820
复制相似问题