如何从客户端向服务器端发送值 [英] How to send values from client side to server side
本文介绍了如何从客户端向服务器端发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从客户端向服务器端发送值?
How to send values from client side to server side?
推荐答案
使用以下链接下载jQuery:
http://ajax.microsoft.com/ajax/jquery/jquery- 1.4.2.min.js [ ^ ]
在你的ASPX页面中包含jQuery。
JS代码:
-----------
Download jQuery by using below link :
http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js[^]
Include jQuery in your ASPX Page.
JS Code :
-----------
function clientSideFunction(myVal) {
try {
.ajax({
type: post,cache: false , async :< span class =code-keyword> false ,url: / yourPage.aspx / serverSideFunction< /秒pan>,data: {'myObject':' + myVal + ,dataType: json,contentType: application / json; charset = udf-8,
成功:函数(r){
如果(rd!= null && rd!= ' '){
alert(rd);
}
}
});
} catch (错误){}
}
.ajax({ type: "post", cache: false, async: false, url: "/yourPage.aspx/serverSideFunction", data: "{'myObject':'"+myVal+"'", dataType: "json", contentType: "application/json; charset=udf-8", success: function (r) { if (r.d != null && r.d != '') { alert(r.d); } } }); } catch (err) { } }
在您的代码页面中写下WebMethod:
-----------------------------
Write WebMethod in your code behind page:
-----------------------------
//Add below namespace in you page
using System.Web.Services;
[WebMethod]
public string serverSideFunction(string myObject)
{
string result = null;
// Write down your code here
return result;
}
这篇关于如何从客户端向服务器端发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文