English 中文(简体)
PHP从来就永远不会恢复4国或200国在阿加西的状态
原标题:PHP never returns readyState 4 or status 200 in ajax

I have the following generic Ajax function:

//run post request
function ajaxPost (divid, parameters, file) {

if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  } else {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

xmlhttp.onreadystatechange=function() {
    alert ("ok")
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      alert ("ready");
      alert (xmlhttp.responseText);
    divid.innerHTML=xmlhttp.responseText;
    }
  }

  xmlhttp.open("POST", file,true);

  //Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", parameters.length);
xmlhttp.setRequestHeader("Connection", "close");



xmlhttp.send(parameters);
}

问题在于本节未按预期运作:

xmlhttp.onreadystatechange=function() {
    alert ("ok")
  if (xmlhttp.readyState==4 && xmlhttp.status==200) {
      alert ("ready");
      alert (xmlhttp.responseText);
    divid.innerHTML=xmlhttp.responseText;
    }
  }

在浏览器中,我像我所期望的那样得到“ok”的警示,但是如果说话永远不会发生火灾的话,我的发言就会得到警示。 我认为这是说,营地正在恢复国家更新,但出于某种原因,从来不恢复现成的法典。 如何做到这一点——我没有想法。

谁能告诉我,为什么我会放弃现成的法典?

The php is not the problem:

<?php

echo "new";

?>

I have tested the function input (divid, parameters and file), and these are ok. This function was previously working in a seperate project.

问题回答
xmlhttp.open("POST", file,true);

file is URL right?
try to echo from that URL.

因此,如果说<条码>xml/http.readyState=4 &&xmlhttp.status=200<>/code>,则永远不会等同,我将冒风险。

Try using Firebug, to see what request is being made (if any) and what response sent re. 如果你不使用“t”一词,则使用“Charles

除此之外,我还高度建议使用一个稳定的开放源 Java文图书馆,如。 这部法律在(除其它事项外)中建立,经过严格测试。 这样做不仅节省了你的时间,而且还将消除你自己的法典中出现错误的可能性,例如,

$.get( url.php , function(data) {
    //  data  is responseText
});

xmlhttp.readyState && xmlhttp.status depend on the browser used, not the PHP script. Worst case, the PHP script might not resturn Status 200, and if this happens means that you either have an error in your script(sometimes this leads to Status 500) or the server returnr a 404. In any case, try accessing the url directly, or look in the firebug log window, it may be easier to debug.

但问题非常简单。 整整周我就座。

页: 1 Http。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签