Javascript “加载资源失败:服务器响应状态为500(内部服务器错误)”

Javascript “加载资源失败:服务器响应状态为500(内部服务器错误)”,javascript,ajax,vb.net,web-services,Javascript,Ajax,Vb.net,Web Services,在使用ajax使用JavaScript调用html页面中的web服务时,我真的无法理解这里的确切问题,因为它会产生以下错误: 加载资源失败:服务器响应状态为500内部服务器错误 Ajax代码: 函数图像{ $.ajax{ 类型:POST,, url:WebService.asmx/GetImage, 数据:{'sDB':'+sDB+'}, contentType:application/json;字符集=utf-8, 数据类型:json, 成功:OnGetMemberSuccess, 失败:函数

在使用ajax使用JavaScript调用html页面中的web服务时,我真的无法理解这里的确切问题,因为它会产生以下错误:

加载资源失败:服务器响应状态为500内部服务器错误

Ajax代码:

函数图像{ $.ajax{ 类型:POST,, url:WebService.asmx/GetImage, 数据:{'sDB':'+sDB+'}, contentType:application/json;字符集=utf-8, 数据类型:json, 成功:OnGetMemberSuccess, 失败:函数errMsg{ $'errorMessage'.TextErrorMsg;//errorMessage是div的id } }; 函数OnGetMemberSuccessdata,状态{ alertdata+data.d; $MemberDetails.htmldata.d; $'input[type=button]'。属性'disabled',false; } } 其中sDB为Null

按钮点击代码:

我在以前的项目中使用了相同的代码,但工作正常

Web服务代码:

<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> <WebMethod()> _
Public Function GetImage()

    Dim cmd As SqlCommand = New SqlCommand
    Dim con = New SqlConnection("server = PROG19-PC;database = XIDBViews;Trusted_Connection = yes")
    cmd.Connection = con
    con.Open()
    Dim strQuery As String = ""
    Dim oSB As New StringBuilder
    Dim table As New Table()
    Dim tr As New TableRow()
    Dim td As New TableCell()
    Dim sFirstNameValue As String = String.Empty
    Dim sLastNameValue As String = String.Empty
    Dim DoBValue As String = String.Empty
    Dim sPhoto As String = String.Empty

    strQuery = "SELECT [sFirstName],[sLastName],[DoB],[sPhoto] FROM [XIDBViews].[dbo].[tblEmployee]  "
    cmd = New SqlCommand(strQuery, con)
    cmd.ExecuteNonQuery()
    Dim dr As SqlDataReader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
    oSB.Append("<table><thead><tr><th>" + " FirstName" + "</th><th>" + "Lastname" + "</th><th>" + "DoB" + "</th><th>" + "Party" + "</th><th>" + "Photo" + "</th></tr></thead>")
    While dr.Read()
        sFirstNameValue = dr("sFirstName").ToString
        sLastNameValue = dr("sLastName").ToString
        DoBValue = dr("DoB").ToString
        sPhoto = dr("sPhoto").ToString

        oSB.Append("<tbody id=tbodyid'>")

        oSB.Append("<tr>")
        oSB.Append("<td class=border1>")
        oSB.Append(sFirstNameValue)
        oSB.Append("</td>")

        oSB.Append("<td class=border1 >")
        oSB.Append(sLastNameValue)
        oSB.Append("</td>")

        oSB.Append("<td  class=border1>")
        oSB.Append(DoBValue)
        oSB.Append("</td>")

        oSB.Append("<td class=border1>")
        oSB.Append(sPhoto)
        oSB.Append("</td>")

        oSB.Append("</tr>")
        oSB.Append("</tbody>")
    End While
    dr.Close()
    con.Close()
    MsgBox(oSB.ToString)
    'Debug.Print(oSB.ToString)
    Return oSB.ToString()
End Function
End Class
但这个web服务代码运行良好,据我所知,问题在于ajax代码,有人能帮我解决这个问题吗。
干杯。

您是否尝试将您请求的URL直接插入浏览器。。。 您将收到一条错误消息,告诉您

只能从脚本调用类定义中具有[ScriptService]属性的Web服务

将[ScriptService]属性添加到服务类定义的顶部,它可能会解决您的问题


我遇到了一个类似的问题,它对我起到了作用:D

将数据类型从json更改为文本修复了我的问题

客户端的javascript错误不会导致500,因为正如代码状态所示,这是一个内部服务器错误。您的服务器端一定有问题。数据:{'sDB':'+sDB+}这一行将以数据结尾:{'sDB':'sDB'},字面意思。这就是你真正的意思吗?谢谢你的回答,我尝试过这个,但它对我不起作用。不,我是在问/通知你,数据部分可能无法按照你的预期工作,字符串文字真的是你想要的吗?是的。我尝试在web服务中将这些值传递给查询,但它对我来说不起作用,所以我尝试了静态方式。