我有一個AJAX調用,它完美地適用於本地服務器。我試圖通過C#(從另一個應用程序/域)進行相同的調用,但我很困惑。將AJAX REST調用轉換爲C#.NET
這是我的webmethod:
[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: " + "'[email protected]'" + ", 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);
}
});
}
重要:
主要的原因我想這是bacause我想消費從另一個域ParentLogin方法。也許從iOS或Android應用程序!這是正確的方法嗎?
謝謝!
這是一個網站,還是一個Web應用程序項目? –
如果您使用的是現成的框架(如JQuery),您可以發佈ExecuteAjaxCall的代碼,或者爲我們確定它所在的JS庫嗎? –
John Saunders:這是一個Web應用程序。 – user2407404