C# 如何进行AjaxCall,以便向服务器发送一些数据(文本)
如何进行C# 如何进行AjaxCall,以便向服务器发送一些数据(文本),c#,jquery,ajax,C#,Jquery,Ajax,如何进行AjaxCall,以便向服务器发送一些数据(文本) 这是我的AjaxCall function AjaxCall() { alert("ajax call made"); sendAjaxRequest({ 'FUNCTION': 'Page_Load' }); } function sendAjaxRequest(jsonData) { jQuery.aj
AjaxCall
,以便向服务器发送一些数据(文本)
这是我的AjaxCall
function AjaxCall()
{
alert("ajax call made");
sendAjaxRequest({ 'FUNCTION': 'Page_Load' });
}
function sendAjaxRequest(jsonData) {
jQuery.ajax({
type: "POST",
async: "false",
url: location.href,
contentType: "application/json; charset=utf-8",
data: (jsonData),
dataType: "text",
success: function (data, textStatus, jqXHR) {
alert("Reply from Server: " + jqXHR.responseText);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Error: " + textStatus + ", " + errorThrown);
},
beforeSend: function (xhr) {
xhr.setRequestHeader("X-OFFICIAL-REQUEST-MINE", "TRUE");
},
complete: function (XMLHttpRequest, textStatus) {
}
});
}
我的c代码
这对我来说非常合适。我想进一步修改它,以便可以向服务器发送一些文本。我该怎么做呢?asp.net中的Web方法怎么样?我没有使用Web方法。此C代码是DotnetNuke模块的一部分,因此它直接执行C代码
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Headers["X-OFFICIAL-REQUEST-MINE"] == "TRUE")
{
AjaxWrapper(sender.ToString());
}
}
protected void AjaxWrapper(string sender)
{
Response.Clear();
Response.ContentType = "text";
byte[] b = Response.ContentEncoding.GetBytes(sender);
Response.AddHeader("Content-Length", b.Length.ToString());
Response.Write(sender);
}