I have made a simple script for showing data from router, but there is an error :
Failed to load resource
But the location is available. So what could be the real cause of the problem.
var xmlhttp = null;
if ( window.ActiveXObject )
{
xmlhttp = new ActiveXObject ( "Microsoft.XMLHTTP" );
}
else
{
xmlhttp = new XMLHttpRequest();
}
xmlhttp.open ( "POST", "http://" + routerIP + port + link, true );
xmlhttp.setRequestHeader ( "Content-type", "application/x-www-form-urlencoded" );
//base64UserPass in format user:pass
xmlhttp.setRequestHeader ( "Authorization", "Basic " + base64UserPass );
xmlhttp.setRequestHeader ( "Connection", "close" );
xmlhttp.onreadystatechange = function()
{
if ( xmlhttp.readyState == 4 )
{
document.write ( xmlhttp.responseText );
}
else
{
alert ( "Error ocurred: server not responding!\n" + xmlhttp.responseText );
}
};
xmlhttp.send ( "" );
For security reasons, you cannot use AJAX to interact with a different domain.
This is completely impossible.
Also jQuery supports ACD (AJAX Cross Domain). Check http://api.jquery.com/jQuery.ajax/ (setting "crossDomain")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.