I have confused about the use of jquery ajax ,what's wrong with my code?
I just begin to learn jquery ajax framework here is my first attempt:
<div>
<input id="ajax" type="button" value="Read" />
</div>
also the js code:
$("#ajax").click(function () {
$.ajax({
type: "get",
url: "http://www.111222333444555.com",
//url: "http://www.google.com"
// timeout: 2000,
success: function () {
alert("ajax success!");
},
error: function () {
alert("ajax failed!");
}
});
});
abviously the "http://www.111222333444555.com" is not accessible,so 开发者_如何学CI consider that resault is alert the "ajax failed!", but the resault is that the success function be executed,which alert "ajax success!"
then I change the url to "http://www.google.com",it alert "ajax success!" as well,
why the accessible url could cause the success function ?how can I escape the situation?I want when the url is not accessible,it will auto execute error function?How the $.ajax exactly works?
Please help me , thank you very much
Using the built-in objects, you cannot use Ajax to request a page that is outside of your page's domain.
There are solutions however...
精彩评论