https://www.doczj.com/doc/9f18307047.html, 前后台数据交互
调研了一天找到了一些向后台传值的方法,还是做事不认
真,忽略了Ajax ,在JQuery 里Ajax 实现也很简单。主要找到
了一些方法,比如用page.registstartup();隐藏域控件传值(出现的问题是js 赋给隐藏控件的value 传不到后台处理程序
中);用Ajax 就比较简单了,$Ajax()里Post()或者Get()设置
参数,后台Request["name"];以后还是要认真学习,做事要认
真仔细,要深入一点。
1.利用JQuery 和Ajax 与后台交互,获取html 控件中内容
或者向html 控件中修改添加内容
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
$(document).ready(function()
{
handle_click("process", ["argument1",
$("#title").val(),"argument2",$("#course_type").val(),"argument3"se_intr").val(),"argument4",$("#teacher_intr").val()], AjaxSuccee AjaxFailed); //With parameters
});
//返回成功时的处理函数
function AjaxSucceeded(result)
{
//alert(result.d);
var obj=new Array();
obj=result.d.split("|");
$("#title").text(obj[0]);
1 5 1 6 1 7 1 8 1 9
2 0 2 1 2 2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 3$("#course_type").text(obj[1]); $("#course_intr").text(obj[2]); $("#teacher_intr").text(obj[3]);
}
// //返回失败时的处理函数
function AjaxFailed(result)
{
alert(result.status + ' ' + result.statusText);
}
function handle_click(fn, argArray, successFn, errorFn)
{
//获取web service 的页面路径
var pagePath = window.location.pathname;
//将argArray中的参数存入argList
//argList中的字符串形式为{"":"","":"","":""}
var argList = '';
if (argArray.length > 0)
{
for (var i=0; i { if (argList.length > 0) argList += ','; argList += '"' + argArray[i] + ' argArray[i+1] + '"'; 0 3 1 3 2 3 3 3 4 3 5 3 6 3 7 3 8 3 9 4 0 4 1 4 2 4 3 4 4 4 5 } } argList = '{' + argList + '}'; //Call the page method $.ajax({ type: "POST", url: pagePath + "/" + fn, //web service 函contentType: "application/json; charset=utf- 要返回json格式数据,而不是整个页面 data: argList, dataType: "json", success: successFn, error: errorFn }); } 6 4 7 4 8 4 9 5 0 5 1 5 2 5 3 5 4 5 5 5 6 5 7 5 8 5 9 6 0 6 6 2 写在html中,process为前面handclick中设定的函数名称,函数中内容为调用C#后台代码 1 2 [System.Web.Services.WebMethod] 3public static string process() 4 { 5// PsyCareLib.psyclassroom.Get_Playvieo_Com mend m = new PsyCareLib.psyclassroom.Get_Playvieo_Comm end(); 6 //string[]new_string = m.Get_Commend(argume nt1); 7 //string[] new_string = new string[2]; 8 //new_string = m.Get_Commend(argument1, arg ument2); 9 PsyCareLib.psyclassroom.distribute_data m = new PsyCareLib.psyclassroom.distribute_data(); 10string new_string = m.get_dsdata(); 11 12//new_string[0] = "data1"; 13 //new_string[1] = "data2"; 14return new_string; 15 16 } 17 2.如果要通过点击不同链接转到另一个页面,或者多个链接对应一个页面。而前台全为html代码,可按上面所写的方法,也可以使用URL拼接的方式获取或者 https://www.doczj.com/doc/9f18307047.html,内置的对象。 比如一个链接:https://www.doczj.com/doc/9f18307047.html,?id=1这个,可以使用Request.Querystring["id"]来获取id对应的1,然后根据这个id号获取其它信息加载到页面中。 在HTML中可以包含服务端脚本,可以使用<%Response.writ e(fun())%>,或者简写为<%=fun()%>,当然fun()应该是有返回值的后台函数。 3.实现一个textbox滚动条始终置底(.net服务端控件页面刷新后仍然置底)。可以使用下面的代码: ?