如何从客户端向服务器端发送值
问题描述:
如何从客户端向服务器端发送值?
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 : false ,url: / yourPage.aspx / serverSideFunction,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;
}