我已经对此进行了搜索并尝试了大量不同的答案,但无法从示例中获取我的代码。
我正在尝试通过ajax向web服务发送用户名和密码。
我的.js是:
$("#btnLogin").click(function () {
var user = $('#username').val();
var pass = $('#password').val();
var myData = {
Username: user,
Password: pass
};
$.ajax({
type: "POST",
url: "plinth/verification/LogMeIn.aspx/VerifyLogIn",
data: JSON.stringify(myData),
contentType: "application/json; charset=utf-8",
dataType: "json",
processdata: true,
traditional: true,
success: callBackFunction,
error: function (msg) { alert(msg); }
});
});
我的LogMeIn.aspx是:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="LogMeIn.aspx.vb" Inherits="AspenBridging.LogMeIn2" %>
<%@ Import Namespace="System.Web.Services" %>
<%@ Import Namespace="System.Collections.Generic" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
<System.Web.Services.WebMethod()>
Public Shared Function VerifyLogIn(ByRef Username As String, ByRef Password As String) As String
Return "Hello!"
End Function
</script>
我目前得到的错误是:
{“Message”:“无法将类型为\ u0027System.String \ u0027的对象转换为 键入\ u0027System.String \ u0026 \ u0027“,”StackTrace“:”at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(对象 o,Type type,JavaScriptSerializer serializer,Boolean throwOnError, Object \ u0026 convertedObject)\ r \ n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(对象 o,Type type,JavaScriptSerializer serializer,Boolean throwOnError, Object \ u0026 convertedObject)\ r \ n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary
2 rawParams)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary
2个参数)\ r \ n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext的 context,WebServiceMethodData methodData,IDictionary`2 rawParams)\ r \ n 在 System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext的 context,WebServiceMethodData methodData)”, “ExceptionType”: “System.InvalidOperationException”}
我已经尝试了大量的东西,我希望它是非常简单的,我忽略了但却无法弄明白。
任何帮助都非常感谢!
答案 0 :(得分:0)
我得到了它的工作。将我的LogMeIn.aspx更改为.asmx(WebService),似乎工作正常。