.net 使用Ajax应用程序/json发布数据,使用ashx文件读取
我以这种方式将此客户变量发送到apiDeneme.ashx。我放置调试点,请求到达apiDeneme.ashx,但是这个电子邮件字符串变量等于null?(下文) 顺便问一下,另一个问题是,像这里这样的登录过程可靠吗?谢谢 请尝试以下代码:-.net 使用Ajax应用程序/json发布数据,使用ashx文件读取,.net,json,stringify,.net,Json,Stringify,我以这种方式将此客户变量发送到apiDeneme.ashx。我放置调试点,请求到达apiDeneme.ashx,但是这个电子邮件字符串变量等于null?(下文) 顺便问一下,另一个问题是,像这里这样的登录过程可靠吗?谢谢 请尝试以下代码:- public void ProcessRequest(HttpContext context) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); string
public void ProcessRequest(HttpContext context)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
string email = context.Request.Form["contact_email"];
sb.Append("[");
sb.Append("{");
sb.Append("\"Sonuc\":\"" + email + "\"}]");
context.Response.ContentType = "application/json";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
context.Response.Write(sb.ToString());
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
并添加[httpost],如下所示:-
$(document).ready(function () {
$('#dropDownMenu1').change(function () {
var customer = { contact_email: "s.selcuk@hotmail.com", company_password: "123" };
$.ajax({
type: "POST",
data: {context : JSON.stringify(customer)},
url: "webServices/apiDeneme.ashx",
contentType: "application/json",
success : function(result) {
alert("called");
}
});
});
});
字符串电子邮件仍然为空,但我无法添加[HttpPost]。Tt给出了一个语法错误。(意思是:红色下划线)。为什么键入[HttpPost]时,Visual Studio没有针对此语法错误的“Resolve..”帮助。最后,电子邮件值仍然为空。由于[HttpPost]的原因,该值是否仍然为空?如果是,如何添加此[HttpPost]而不出现任何语法错误?
$(document).ready(function () {
$('#dropDownMenu1').change(function () {
var customer = { contact_email: "s.selcuk@hotmail.com", company_password: "123" };
$.ajax({
type: "POST",
data: {context : JSON.stringify(customer)},
url: "webServices/apiDeneme.ashx",
contentType: "application/json",
success : function(result) {
alert("called");
}
});
});
});
[HttpPost]
public void ProcessRequest(HttpContext context)
{
}