1

I'm developing a chrome extension, tried to post a page's title & content to a server, with following code in the popup.js, but found req.open throws out DOMException ( invalide state as code 11). And, I already add permission as "permissions": [ "tabs", "http://*/*", "https://*/*"], it still dosent work. How can I fix this?

function addBookmark()
{
var req = new XMLHttpRequest();

req.open("POST", "remote_sever_url/quote/new", true);

var params  = "title=" + document.getElementById("title").value + 
            "&text=" + document.getElementById("text").value +
            "&url=" + document.getElementById("url").value + 
            "&tags=" + document.getElementById("tags").value;

req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.setRequestHeader("Content-length", params.length);
req.setRequestHeader("Connection", "close");

req.send(params);
Mohsen
  • 64,437
  • 34
  • 159
  • 186
jarodtang
  • 11
  • 3
  • Maybe you should encode your params with `encodeURIComponent` – Mohsen Oct 17 '12 at 19:33
  • Your code, as posted, works fine for me. Are you sure that the error is not happening on a later line? Do you ever attempt to access the `status` or `responseText` properties of `req` outside of a `onreadystatechange` or `onload` handler? See the second answer to this question: http://stackoverflow.com/questions/3488698/invalid-state-err-dom-exception-11-webkit – apsillers Oct 17 '12 at 19:59
  • 1
    Possible duplicate of [Error on sending POST request](http://stackoverflow.com/questions/31248717/error-on-sending-post-request) – Paul Sweatte Sep 01 '16 at 16:12

0 Answers0