[英]Ajax call from dropdown select
I am trying to make an Ajax request to the page specified in the drop down menu. 我正在尝试向下拉菜单中指定的页面发出Ajax请求。 I have successfully used most of my script code in binding a mouse click to table rows, but it does not work in this case when I try it here.
我已经成功地将我的大部分脚本代码用于将鼠标单击绑定到表行,但是在这种情况下,当我在此处尝试操作时,它将无法正常工作。 I get ReferenceError: fnsuccess is not defined.
我收到ReferenceError:未定义fnsuccess。 I did not get this ReferenceError when I used most of this script to bind a mouse click.
当我使用此脚本的大部分来绑定鼠标单击时,没有得到此ReferenceError。
<script type="text/javascript">
function isValid(frm){
$("#courseinfo").hide();
$("#frm").validate();
var four04 = $("#frm :selected").val();
console.log('Testing console');
if (four04 == "404")
{
console.log("404");
var txt = ($(this).text());
$.ajax({url:"404.json", data:{coursename:txt}, type:"GET", dataType:"json",
success:fnsuccess, error:fnerror});
function fnsuccess(serverReply) {
if (serverReply && serverReply.info) {
$("#infohere").text(serverReply.info);
$("#courseinfo").show();
} else
fnerror();
}
function fnerror() {
alert("Error occurred");
$("#courseinfo").hide();
}
}
else
{
console.log("else 404");
}
}
</script>
Course --> Rating 404 error 403 error
Fix: 固定:
<script> function isValid(frm){ $("#otherPageContent").hide(); $("#frm").validate(); var dropDownSelected = $("#frm :selected").val(); if (dropDownSelected == "404") { var txt = ($(this).text()); $.ajax({url:"404_error.json", data:{coursename:txt}, type:"GET", dataType:"json", success:fnsuccess, error: function(xhr, status, error){ $("#infohere").text( "The requested page was: 404_error.json" + ". The error number returned was: " + xhr.status + ". The error message was: " + error); $("#otherPageContent").show(); } }); // end of ajax } // end of if 404 function fnsuccess(serverReply) { if (serverReply && serverReply.info) { $("#infohere").text(serverReply.info); $("#otherPageContent").show(); } } return false; // pause message on screen } </script>
在isValid function
外部定义function fnsuccess(serverReply)
和fnerror
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.