应该很简单。我已经阅读了很多关于使用Web服务跨域和使用JSONP的帖子,但是我有些遗漏。
如果我在WebBrowser中调用以下URL,我可以得到我的结果: http://benfaniz.com.br/WebService.asmx/AAA_Buscar_Nome_Condominio?callback=?
要使用jQuery使用它,我正在使用:
$(document).ready(function() {
var surl = "http://benfaniz.com.br/webservice.asmx/AAA_Buscar_Nome_Condominio";
$.ajax({
type: 'POST',
url: surl,
dataType: "jsonp",
success: function(msg) {
alert(msg.data);
},
error: function(xhr, status, error) {
alert("error");
}
});
});
以下是JS Fiddle
但我一直收到错误?有什么问题?
更新
我可以使用以下代码(取自here)
获取网址的内容 $(document).ready(function() {
var theUrl = "http://benfaniz.com.br/WebService.asmx/AAA_Buscar_Nome_Condominio?callback=?"
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET", theUrl, false );
xmlhttp.send();
});
请查看JS Fiddle
答案 0 :(得分:1)
我能做到。我发现这个问题here给了我指示。
主要问题是我得到的是XML结果而不是JSON。要更改此设置,我必须添加第@media only screen and (min-device-width : 414px) and (max-device-width : 736px) {
p.style3 {
font-size: 3rem !important;
font-family: Georgia, "Times New Roman", Times, serif !important;
text-rendering: optimizeLegibility;
font-style: italic;
font-weight: lighter;
white-space: nowrap;
}
}
行。
最终代码如下:
contentType: "application/json; charset=utf-8"