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

前台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>

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。