我从一个浏览器扩展程序内容脚本发送到POST
我控制的服务器。我在清单中设置好权限。这是我的XHR代码。 (我想避免这个jQuery)。它发送一个空responseText
XHR在Chrome扩展与CI
var xhr = new XMLHttpRequest();
xhr.open("POST",'http://mysite.com/make',true);
xhr.onreadystatechange=function() {
if (xhr.readyState == 4) {
var res = JSON.parse(xhr.responseText);
console.log(res);
}
}
xhr.send({'textbox':data[0].user,'from':'extension'});
data[0].user
是一个对象,我在CI控制器直接得到了来自Twitter的API
我
$user = $this->input->get_post('textbox', TRUE);
$from = $this->input->get_post('from', TRUE);
$fullURL = 'http://www.google.com'; //example of a URL from code.
$json = $this->output->set_content_type('application/json');
$json->set_output(json_encode(array('URL' => $fullURL)));
响应文本为空
,另一方面jQuery的电话正常工作
$.post("http://mysite.com/make", { 'textbox': data[0].user, 'from':'jquery' },
function(data) {
console.log(data);
});
是否使用萤火/铬开发工具? 签出服务器正在发送什么响应? 并退后一步..尝试记录什么JSOn字符串是PHP生成? –
我安装了[chromePHP](http://www.chromephp.com/)。将尝试调试。 – Chamilyan
但在此之前刚刚尝试 xhr.post( “文本=” +数据[0]的.user + “&从扩展=”); 而不是你所做的。 我认为它应该工作。 –