javascript - Using a specific URL in XMLHttpRequest, return NetworkError: A network error occurred -


var xmlhttp = new xmlhttprequest; if (!xmlhttp) {     alert ("xmlhttprequest create error"); } xmlhttp.open ("get", "http://127.0.0.10/advert/123", false); xmlhttp.onreadystatechange = function () {      if (xmlhttp.readystate == 4) {         console.log (xmlhttp.status);         if (xmlhttp.status == 200) {             console.log (xmlhttp.responsetext);         } else {             alert ("error");         }     } }; xmlhttp.send (); 

the specific url '//host/advert/???'. like:

//127.0.0.12/advert/123

//127.0.0.12/advert/test

and more...

only using url, mistakes come up.

the specific url env php+apache(rewrite), code this:

index.php

echo 123; exit; 

.htaccess

rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^(.*)$ index.php/$1 [qsa,pt,l] 

you're mixing usage of synchronous , asynchronous requests.

if you're passing false 3rd parameter open method, meaning request should synchronous (why, btw?), should process this:

xmlhttp.open("get", "http://127.0.0.10/advert/123", false); xmlhttp.send(null);  if (xmlhttp.status === 200) {   console.log(xmlhttp.responsetext); } 

additional information: synchronous , asynchronous requests


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -