首页 > Web开发 > 详细

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

时间:2014-10-21 17:16:42      阅读:315      评论:0      收藏:0      [点我收藏+]

前台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调用后台方法的一种方法

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!