我是 javascript 和 AJAX 的新手,过去 8 个小时都在解决这个问题,这让我很困惑。我知道这很简单,只是找不到我做错了什么。我的网站上有一个带有 on-click=SendCommand() 的图像。这是我的js代码
function SendCommand(){
alert("BingoBango!");
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","https://www.justanexample.com/API/MobileAPP/SendCommand.php?apikey=7785adf3a5d3a3adsf555nb5v55bsaer5v&mac=b827eb6ffa19&command=2",true);
xmlhttp.send();
};
我收到警报消息,并且使用 firebug 或在 chrome javascript 控制台中没有收到任何错误。但是该页面未执行。不过,我可以将该确切的网址复制并粘贴到浏览器中,并且它会成功执行。
任何帮助将不胜感激,它让我很高兴。
最佳答案
The page it is calling is calling a python script as well as updating a mysql record. Is there something i can do in my request to ask it to not use the browser cache and actually hit my server?
您不应该对在服务器上执行操作的事物使用 GET
请求。使用 POST
代替,should not be cached .
如果这没有帮助,请调整您的 HTTP cache headers或者,作为最后的手段,将随机字符串附加到 URL。
关于javascript - XMLHttpRequest 不执行任何操作....?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21587970/