从Jquery调用ASP服务

时间:2014-01-28 22:45:58

标签: jquery asp.net ajax

我正在尝试设置一个接受字符串并返回字符串的简单服务。我已经构建了ASP.net代码并使用它内置的测试页面,但似乎无法从jquery调用该服务。

ASP:

<System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="https://domain/decode")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Decode
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function Decode(Image64 As String) As String

        Dim Code As String = "test"
        Return Code
    End Function

End Class

然后我试图在现有的php页面上从jquery调用此服务:

<script src="js/jquery-1.9.1.js"></script>
<script language="javascript" type="text/javascript">
$(function() {

           $.ajax({
               type: "POST",
               url: "https://domain/decode/decode.asmx/Decode",
               data: {Image64: ""},
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               success: OnSuccess,
               error: OnError

       });
 });
       function OnSuccess(data, status)
       {
          alert(data.d);
       }

       function OnError(request, status, error)
       {
           alert(request.statusText);
       }

我尝试更改数据格式data: "{}"等,并且我一直收到“内部服务器错误”。

我认为ASP方面可能出现问题,因为我对此完全陌生,但无法弄清楚是什么......

1 个答案:

答案 0 :(得分:0)

好吧,不使用native,但找到了一个很棒的SOAP插件:https://github.com/doedje/jquery.soap

现在工作正常=)

相关问题