Ajax send function wont' fire?

Whenever I run this file the code runs up to the point where the send function fires and then it only fires if I have an alert function directly behind it, if I take out the alert("sent"); out then it replies with `ServerReadyyState` is:1. What could possibly be the problem? Someone please help, I've tried it on my local machine and on my personal server and got the same results. Any help is greatly appreciated. The Code: /** * @author d */ var xhr; function getPlants(xhr) { try { xhr = new XMLHttpRequest(); } catch (microsoft) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch (othermicrosoft) { try { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } catch (failed) { xhr = false; alert("ajax not supported"); } } } xhr.open("GET", "db_interactions.php", true); xhr.send(null); alert("sent"); //the send function only works if this alert functions is here if (xhr.readyState == 4) { return xhr.responseText; } else { alert("Server ReadyState is:" + xhr.readyState); xhr.abort(); //getPlants(xhr); } }

以上就是Ajax send function wont' fire?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准