我有一个非常基本的 - 用于测试 - 用 VB 编写的 ASP.net Web 服务(2.0 和 IIS 6.0)在远程服务器上运行
网络服务
<WebService(Namespace:="CMS_ChecklistSystemWebService")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()> _
Public Class CMS_ChecklistSystemWebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
配置。
我必须将以下这些行添加到我的 webservice
配置中,以便能够在浏览器中运行 webservice
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
**网络服务结果**
我尝试使用 AJAX
JQUERY
运行 XAMPP 从
PHP
页面调用此 web 服务
v3.1
JQUERY
$.ajax({
type: "GET",
url: "http://192.168.25.11/link to web service",
data: "",
dataType: "jsonp",
contentType: "application/jsonp; charset=utf-8",
success: function(data) {
console.log(data);
}
});
错误
以下是调用 ajax()
函数后我的控制台的样子
仅供引用,如果我单击第二行中的链接,它会将您链接到 webservice
并像在第一张图片中那样运行它
注意
如果我使用来自同一项目的相同 webservice
- 域 - 我可以轻松地执行 ajax()
调用和 type='json'
它完美无误地工作
问题
- 我做错了什么?
- 我是否需要让
Webservice
返回一个JSON
对象而不是XML
如果是,那么如何
最佳答案
我认为问题在于,您在 ajax 调用中将内容类型指定为 json。但是,您的网络服务正在返回 xml。
因此,您可以在ajax 调用中将内容类型指定为xml 并处理xml(我不确定是否可行),或者您可以将web 服务配置为返回json。
引用这个 SO 问题 ( How to return JSON from a 2.0 asmx web service ) 配置 web 服务返回 json。
关于c# - 使用 ajax() 和 jsonp 调用 asp.net 远程 webservice .asmx 时出现意外标记 <,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16483224/