XMlHttpRequest 在 Firefox 扩展中不起作用
XMlHttpRequest is not working in Firefox extension
以下代码在Google Chrome中运行良好,但在Firefox中无法正常工作。我无法发出请求,也无法收到回复。 我不知道问题出在哪里?
这是我的Javascript代码。
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
// alert(str);
xmlhttp.open("GET","server url/folder/file.php?q="+"string",true,"user","password");
alert();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert("response");
alert(xmlhttp.responseText);
var string=xmlhttp.responseText;
}
}
xmlhttp.send();
这是我的服务器脚本,它会响应。
<?php
header('Access-Control-Allow-Origin: *');
$q=$_GET["q"];
echo $q;
?>
如果你像这样添加X-Requested-With
标题怎么样:
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
我也会使用xmlhttp.send(null);
因为一些旧的 Firefox 浏览器需要null
参数。最后一件事:在我第一次宣布onreadystatechange
听众之前,我不会打电话给xmlhttp.open
。
祝你好运,希望这有帮助。
您是否
尝试过在调用发送之前设置内容类型?
喜欢这个
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
相关文章:
- o数据扩展查询在SystemUserRolesSet上不起作用
- 正在处理在chrome扩展中不起作用的js
- 为什么这个扩展方法不起作用
- 为什么我的谷歌浏览器扩展程序在谷歌浏览器版本 41.0.2272.89 中不起作用
- Chrome 扩展程序权限不起作用
- Chrome 扩展 cookies.getAll 不起作用
- List.JS 在通过 Chrome 扩展程序注入时不起作用
- 设置Sails js视图扩展不'不起作用
- 使用jQuery的Chrome扩展不起作用
- chrome扩展名“sendResponse”不起作用
- 基本的谷歌chrome扩展消息传递不起作用
- $(document).click()在chrome扩展中不起作用
- Javascript在Google Chrome扩展的选项页中不起作用
- 在chrome扩展的弹出窗口中,警报不起作用
- firefox扩展对$.ajax的调用不起作用
- I'我试图制作一个chrome查找和替换扩展,但它赢了;不起作用
- chrome扩展弹出相同的选项卡仍然不起作用
- Javascript按钮单击在Chrome扩展弹出窗口中不起作用
- Google Chrome扩展:setAttribute没有'不起作用
- 验证不起作用(扩展)