我有一个在本地服务器上完美运行的 AJAX 调用。我正在尝试通过 C#(来自另一个应用程序/域)进行相同的调用,但我很困惑。
这是我的网络方法:
[WebMethod(true)]
public static object ParentLogin(string email, string password)
{
List<object> ChildrenList = new List<object>();
Usuario loggedUser = GetByEmailAndPass(email, password);
if (loggedUser != null)
{
var children = Factory.Current.GetInstance<IChildrenBIZ>().GetAll().ToList();
foreach (var item in children )
{
ChildrenList.Add(new { userid = item.Id, name = item.Nome });
}
return new { success = true, email = loggedUser.Login, users = ChildrenList};
}
return new { success = false };
}
这是我的ajax调用:
var url = "http://localhost/" + "LoginTest/Login.aspx/ParentLogin";
var dataParams = "{ email: " + "'myemail@hotmail.com'" + ", password: " + "'123123'" + " }";
ExecuteAjaxCall(url, dataParams, true, function (msg) {
if (msg.d) {
var success = msg.d.success;
var children = msg.d.users;
if (children.length > 0) {
$.each(children, function (i, item) {
if (item) {
var childID = item.userid;
}
});
}
}
}, StandardError);
});
现在我想通过后面的代码调用这个相同的 Webthod。我尝试了使用 Restsharper,但我无法实现。请问有人吗?
编辑:
这是 ExecuteAjaxCall 方法:
function ExecuteAjaxCall(url, dataParam, isAssync, callBackSucess, callBackError) {
$.ajax({
type: "POST",
url: url,
data: dataParam,
contentType: "application/json; charset=utf-8",
dataType: "json",
assync: isAssync,
success: function (msg) {
callBackSucess(msg);
},
error: function (msg) {
callBackError(ERROR_MSG);
}
});
}
重要的:
我想要这个的主要原因是因为我想从另一个域使用 ParentLogin 方法。可能来自 iOS 或 Android 应用程序!这是正确的方法吗?
谢谢!