I am trying to make an Ajax request to the page specified in the drop down menu. 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. I did not get this ReferenceError when I used most of this script to bind a mouse click.
<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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.