Post (XMLHttpRequest) javascript does not work

0

Personal I'm developing an extension for Chrome, but the post part is not working. The information does not arrive. will the problem be the extension.

chrome.extension.onMessage.addListener(function(request, sender) {
if (request.action === "getSource") {
    var message, data, xhr;

    message = document.querySelector("#message");
    data = request.source;

    message.innerText = "Enviando ao servidor...";

    var postUrl = 'webservice.php';

    xhr  = new XMLHttpRequest();
    xhr.open('POST', postUrl, true);
    xhr.onreadystatechange = function() {
        if(xhr.readyState === 4) {
            if (xhr.status === 200) {
                message.innerText = "Resposta do servidor: " + xhr.responseText;
            } else {
                message.innerText = "Err: " + xhr.status;
            }
        }
      };

    //Enviando dados como RAW
    xhr.send(request.source);
     }
   });


function onWindowLoad() {

 var message = document.querySelector('#message');

 chrome.tabs.executeScript(null, {
 file: "getPagesSource.js"
 }, function() {

    if (chrome.runtime.lastError) {
    message.innerText = 'There was an error injecting script : \n' +   chrome.runtime.lastError.message;
   }
   });

    }

    window.onload = onWindowLoad;

webservice.php

<?php

 $rt = $_POST['data'];
 $fp = fopen("bloco1.txt", "a");


 $escreve = fwrite($fp, '$rt');

 // Fecha o arquivo
 fclose($fp);

 ?>  
    
asked by anonymous 10.09.2018 / 17:32

0 answers