Reputation: 83033
I have code that looks something like this:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
function myButton_click(){
alert('got here');
$.get("myPage.cfm", function(data){alert('load was performed')});
}
</script>
</head>
<body>
<input type="button" id="myButton" value="My Button" onClick="myButton_click()" />
</body>
</head>
The first alert ("got here") shows up, but the "load was performed" doesn't. Is the get being executed? What am I doing wrong?
Edit:
I've tried it with "http://www.google.com" instead of "myPage.cfm" to make sure it's not a problem with my page and it's still not alerting...
Upvotes: 0
Views: 137
Reputation: 41757
The callback only executes on success (Http status code in the 200s or 304), try using the longhand jQuery.ajax method and following the advice in this SO question for how to handle this response in a reasonable manner.
Upvotes: 0
Reputation: 89566
According to the docs, the function you pass as the second parameter to the $.get
call is only called on success. So if your server is returning any kind of error (400, 403, 404, 500 etc.), that function will not be called. If you want a function to be called no matter what, use complete
:
$.get("myPage.cfm").complete(function(jqXHR, textStatus) {
alert("Load was performed");
});
Upvotes: 1