【问题标题】:Getting "NetworkError: 500 Internal Server Error" when calling a webserver using jquery ajax使用 jquery ajax 调用网络服务器时出现“NetworkError:500 Internal Server Error”
【发布时间】:2015-06-24 23:57:09
【问题描述】:

我正在尝试使用 ajax 调用网络服务。 Web 服务是用 vb.net 编写的。当我使用它的 url 直接调用它时它工作正常,但是当我使用 ajax 调用它时它返回

NetworkError:500 内部服务器错误-http://localhost/chart/webService.asmx/HelloWorld。

这是我的网络服务代码:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class webService
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class

这里是javascript代码:

$(document).ready(function() {
    var webMethod = 'http://localhost/chart/webService.asmx/HelloWorld';
    $.ajax({
        type: "POST",
        url: webMethod,
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            alert('all good');
        },
        error: function(e) {
            alert('err');
        }
    });
});

更新:

我将 HelloWorld() 更改为以下代码,但仍然出现相同的错误:

<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function HelloWorld() As String
    Dim aa As New System.Web.Script.Serialization.JavaScriptSerializer
    Return aa.Serialize("Hello World")
End Function

【问题讨论】:

  • 你的函数 *hello_world" 没有返回 json 对象。
  • 更新后可能会发布。但还是报错
  • 你试过在浏览器中访问它吗?
  • 是的。当我在浏览器中访问它时它工作正常
  • 错误日志怎么样 - 500 通常表示它是内部错误,如果没有,请制作您的服务器端代码转储日志

标签: jquery ajax vb.net web-services


【解决方案1】:

用途:

data:{},

代替:

data:"{}",

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    • 1970-01-01
    • 2014-10-23
    • 2013-01-08
    • 1970-01-01
    • 2020-02-01
    • 2011-09-22
    相关资源
    最近更新 更多