码迷,mamicode.com
首页 > Web开发 > 详细

js调用后台方法的一种方法

时间:2014-10-21 17:18:43      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   ar   java   sp   on   cti   html   

前台js方法:

<script language="javascript" type="text/javascript">
function search(typeStr, value,judge) {
PageMethods.searchCondition(typeStr, value,judge, taskCompleted, taskFailed);
}
function taskCompleted(results, context, methodName) {
window.location.href = results;
this.f
}
function taskFailed(results, context, methodName) {
alert("发生错误异常!");
}
</script>

方法支持:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>

后台方法:

[WebMethod]
public static string searchCondition(string typeStr, string value, string judge)
{
if (typeStr == "quyu")
{
quyuVal = value;
if (judge == "1")
{
zquyuVal = "";
}
}
else if (typeStr == "good")
{
leixingVal = value;
}
else if (typeStr == "zhuti")
{
zhutiVal = value;
}
else if (typeStr == "fangshi")
{

fangshiVal = value;
}
else if (typeStr == "zquyu")
{

zquyuVal = value;
}

string goUrl = "www.baidu.com";

return "Pro_View.aspx?quyu=" + quyuVal +"&zquyu="+zquyuVal+ "&good=" +leixingVal + "&zhuti=" + zhutiVal + "&fangshi=" + fangshiVal + "&math=" + new Random().Next(1000, 100000);
//return "TourRoute.aspx?name=" + daysVal;
}

HTML调用js方法:

<p onclick=\"search(‘参数1‘,‘参数2‘,‘参数2‘)\" >点击执行方法</p>

js调用后台方法的一种方法

标签:style   color   io   ar   java   sp   on   cti   html   

原文地址:http://www.cnblogs.com/lzyp/p/4040769.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!