c# - 使用 ajax() 和 jsonp 调用 asp.net 远程 webservice .asmx 时出现意外标记 <

标签 c# ajax vb.net web-services jsonp

我有一个非常基本的 - 用于测试 - 用 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>

**网络服务结果** enter image description here

我尝试使用 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() 函数后我的控制台的样子 enter image description here

仅供引用,如果我单击第二行中的链接,它会将您链接到 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/

相关文章:

vb.net - 2010 年的 Visual Basic PowerPack 在 2013 年不起作用?

c# - 如何使用Lync SDK通过邮件判断是否存在合法的Lync用户?

c# - 使异步 API 同步

c# - 为什么我的C#程序无法识别长度?

c# - 在 asp.net core 中使用 NVarChar

javascript - xmlhttprequest headers 定义的含义

php - 如何将 $_GET 路径与 file_exists 一起使用并保证其安全?

javascript - 下拉自动完成

c# - 将 My.Application.Deployment.ActivationUri 转换为 C#

windows - 将 VB.Net 应用程序转换为服务