Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLHttpRequest in chrome extensions

How to send and recieve info from php file with XMLHttpRequest?

I try using XMLHttpRequest and jquery ajax. In both cases work find, but I can't extract the data.

Js file

var parametros = {
            "url" : url
    };

  var xhr = new XMLHttpRequest();
  xhr.open("POST", "file.php", true);
  xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {

    alert(xhr.responseText)
  }
}
xhr.send(parametros);

file.php

  <?php 
$str = $POST['url'];
echo $str;

    ?>

The alert show me all the php file, with php tags (plain text). How to recieve only the $str var?

EDIT: manifest file:

{
  "name": "Get pages source",
  "version": "1.0",
  "manifest_version": 2,
  "description": "Get pages source from a popup",
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": ["http://localhost/extencio/*"]
}
like image 441
Phyron Avatar asked Sep 01 '25 05:09

Phyron


1 Answers

That sounds more like an error on webserver, are you sure your webserver is executing the php file? You could test this by going to the location of the php file with your browser.

If it also shows all of the PHP in your webbrowser, take a look at this question: PHP code is not being executed, instead code shows on the page

like image 158
Mathijs Avatar answered Sep 02 '25 18:09

Mathijs