Cordova使用ASP.NET WebService(.asmx)而不是woking

时间:2015-02-14 16:14:15

标签: asp.net vb.net web-services cordova

我在使用cordova和.asmx作为我的后端代码时遇到了麻烦。它总是返回undefined错误。

这是我的jQuery代码:

$('#signin').click(function (e) {
        $('#frmLogin').validate();

        $('#uid').rules('add', {
            required: true,
            messages: {
                required: 'Input your username.'
            }
        });

        $('#upassword').rules('add', {
            required: true,
            messages: {
                required: 'Input your password.'
            }
        });

        if ($('#frmLogin').valid()) {
            var credentials = {}
            credentials.username = $('#uid').val();
           credentials.password = $('#upassword').val();

            $.ajax({
                type: 'POST',
                url: 'http://localhost/WebService/WebService.asmx/Signin',
                data: JSON.stringify(credentials),
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
            return false;
        }
    });

这是.asmx文件

中的代码
<System.Web.Script.Services.ScriptService()> _
<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 Signin(ByVal username As String, ByVal password As String) As String
    Dim AccountStatus As String = (New Account.Membership).GetAccountStatus(username, password)

    Return AccountStatus
End Function
End Class

应该假设返回AccountStatus值内的内容。

更新

这是控制台中的错误返回

  

rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//localhost/WebService/WebService.asmx%3Fop%3DSignin:1 POST https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//localhost/WebService/WebService.asmx%3Fop%3DSignin 500(内部服务器错误)

更新:已解决

我现在明白了。我刚刚添加了

<system.webServer>
    <httpProtocol>
        <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Headers" value="Content-Type" />
        </customHeaders>
    </httpProtocol>
</system.webServer>
<{1>}文件中的

感谢您的帮助。

0 个答案:

没有答案