简体   繁体   中英

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/*"]
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM