JQuery的阿贾克斯投递到C# [英] JQuery Ajax Post to C#
本文介绍了JQuery的阿贾克斯投递到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找回JSON对象在这里C#是我JavasSciprt后,但我不能喊得它在codebehind,谢谢!
$。阿贾克斯({
键入:POST,
网址:脸谱/ addfriends.aspx
数据:{数据:response.data},
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON,
成功:函数(MSG){
位置='/ Facebook的/登录URL ='+ RETURNURL +'和; UID ='+ response.authResponse.userID +'和; TK ='+ response.authResponse.accessToken +'';
}
});
我试着像检索数据:
的Request.Form [数据]
请求[数据]
解决方案
下面是从的 Encosia.com (我加了一个表单参数)。你并不需要访问 Page.Form
- 您可以使用方法参数,而不是
codebehind
公共部分类_Default:页
{
[WebMethod的]
公共静态字符串GETDATE(字符串someParameter)
{
返回DateTime.Now.ToString();
}
}
Javascript的
$(文件)。就绪(函数(){
//添加页面的方法调用作为一个onclick处理程序分区。
$(#结果)。点击(函数(){
$阿贾克斯({
键入:POST,
网址:Default.aspx的/ GETDATE
数据:{someParameter:一些价值},
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON,
成功:函数(MSG){
//替换div的内容与页面方法的返回。
$(#结果)文本(msg.d)。
}
});
});
});
I'm trying to retrieve JSON Object on C# here is my JavasSciprt post but I'm unable to hande it on codebehind, thanks!
$.ajax({
type: "POST",
url: "facebook/addfriends.aspx",
data: { "data": response.data },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
location = '/facebook/login?URL=' + ReturnURL + '&UID=' + response.authResponse.userID + '&TK=' + response.authResponse.accessToken + '';
}
});
I've tried to retrieve data like:
Request.Form["data"]
Request["data"]
解决方案
Here's an example from Encosia.com (I added a form parameter). You don't need to access Page.Form
- you can use method parameters instead.
Codebehind
public partial class _Default : Page
{
[WebMethod]
public static string GetDate(string someParameter)
{
return DateTime.Now.ToString();
}
}
Javascript
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: {someParameter: "some value"},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
}
});
});
});
这篇关于JQuery的阿贾克斯投递到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文