Tuesday, 15 September 2015

javascript - Server not available -


If I have a code that calls a php file from a remote, then how and where "server is not available" Add message? Server but PHP file is missing? Here's my code:

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script language = "javascript" & gt; View functions () {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 () {if (xmlhttp.readyState == 4 & xmlhttp.status == 200} {document.getElementById ("Detorible"). InnerHTML = xmlhttp.responseText; } Xmlhttp.open ("post", "http: //someremoteserver/somephpfile.php", true); Xmlhttp.setRequestHeader ("content-type", "app / x-www-form-urxed"); Xmlhttp.send (); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body onload = "see ();" & Gt; & Lt; Div id = "datatable" align = "center" & gt; & Lt; / Div & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

You can find out individually and do something on the basis of feedback . Or if you do not have a position 200 then you can apply a normal handler:

  if (xmlhttp.readyState == 4) {if (xmlhttp.status == 200) {document.getElementById ("Datatable") innerHTML = xmlhttp.responseText. } And if (xmlhttp.status == 503) {// Special Error Code Warning ('Sorry, this server is unavailable'); } Else {// General Error Handler Alert ('There was an error with your request'); }}    

No comments:

Post a Comment