Posting plain text on php using JavaScript -


i need use "post" consisting of value , variable structure using javascript. plain text should sent php page displayed. how should this?

from understand according requirement. needs submission, run using javascript.

document.body.innerhtml += '<form id="content" action="http://10.10.10.10/index.php" method="post"><input type="hidden" name="info" value="'+plaintext+'"></form>'; document.getelementbyid("content").submit(); 

i tried code well.do have idea on how display text sent here on php page?

var request = new xmlhttprequest(); request.open("post", "10.10.10.10/index.php", true);  request.onreadystatechange = function () {      if(request.readystate === 4){          if(request.status === 200 || request.status == 0){                 request.setrequestheader("content-type","text/plain;charset=utf-8");             request.setrequestheader("content-length", plaintext.length);              request.send(plaintext);          }     } } request.send(null); 

you need use ajax, if need plain javascript should this:

var request = new xmlhttprequest(); request.onreadystatechange = function () {     var done = this.done || 4;     if (this.readystate === done){         alert(xhr.responsetext);     } }; request.open('post', 'script.php', true); request.send("<your text>"); 

if use jquery simple:

$.post('script.php', '<your text>', function(response) { }); 

and can read in php using:

file_get_contents('php://input'); 

or (deprecated):

$globals['http_raw_post_data']; 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -