我怎样才能动态地将数据从HTML窗口传递到窗口后面的代码 [英] How can i pass dynamically datas to Code behind window from html window
本文介绍了我怎样才能动态地将数据从HTML窗口传递到窗口后面的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个asp.net项目.我正在使用一个jQuery ajax代码将数据从HTML窗口传输到窗口(C#)后面的代码.
当我以硬编码方式传输数据时,它工作正常.如何动态传输数据.
在下面的示例中,我将登录名硬编码为"login123",并将其传递为"pass123".我需要动态传递数据.
我该怎么办..请帮助我...
Hi,
I am doing a asp.net project. and i am using a jquery ajax code to transfer data from HTML window to code behind window (C#).
When i transfer the datas in hard coded then it is working fine. how can i transfer the datas dynamically.
Here the below example i have hard coded the login as "login123" and pass as "pass123" . I need to pass the datas dynamically.
How can i do it.. please help me...
// Html window Code
$.ajax({
type: "POST",
url: "kchnLogin.aspx/Test",
data: JSON.stringify({ login: 'login123', pass: 'pass123'}),
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (output) {
formLogin.clearMessages();
displayError(output.d);
}
});
//C# Code on code behind window
[WebMethod]
public static string Test(string login, string pass)
{
return "Invalid User / Password, Please Try Again";
}
谢谢,
Dileep ..
Thanks,
Dileep..
推荐答案
.ajax({ 类型:" , 网址:" , 数据: JSON .stringify({登录:' login123' ,通过:' pass123'}), contentType:" , dataType:" , 异步: true , 成功:功能(输出){ formLogin.clearMessages(); displayError(output.d); } });
.ajax({ type: "POST", url: "kchnLogin.aspx/Test", data: JSON.stringify({ login: 'login123', pass: 'pass123'}), contentType: "application/json; charset=utf-8", dataType: "json", async: true, success: function (output) { formLogin.clearMessages(); displayError(output.d); } });
//C# Code on code behind window
[WebMethod]
public static string Test(string login, string pass)
{
return "Invalid User / Password, Please Try Again";
}
谢谢,
Dileep ..
Thanks,
Dileep..
如果它可以进行硬编码,则问题不在于客户端与服务器之间的通信,而在于如何在javascript中检索数据并发送它是一个问题.粘贴用于发送动态数据的代码.
If it works hardcoded then the problem is not in client-server communication, rather it''s a problem in how you retrieve the data in your javascript and send it. Paste the code that you use to send dynamic data.
这篇关于我怎样才能动态地将数据从HTML窗口传递到窗口后面的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文