javascript - Send data to PHP popup page -


i want send input type element php page without form submission, javascript. tried $.ajax no way. don't know if syntax or logical error. told me single php page instead of two.

html page: (but .php)

<!doctype html> <html lang="en"> <head>   <title>bootstrap example</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">   <script src="../../js/jquery-3.2.0.min.js"></script>   <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>   <style>       #prova{           padding-right: 1%;           padding-top: 1%;        }     </style>     <script> function ajax_post(apri){     var stile = "top=10, left=10, width=650, height=600, status=no, menubar=no, toolbar=no scrollbars=no";     // create our xmlhttprequest object     var hr = new xmlhttprequest();     // create variables need send our php file     var url = "sperem.php";     var fn = document.getelementbyid("id_buyers").value;     alert(fn);     var vars = "postid="+fn;     alert(vars);     hr.open("post", url, true);     // set content type header information sending url encoded variables in request     hr.setrequestheader("content-type", "application/x-www-form-urlencoded");     // access onreadystatechange event xmlhttprequest object     hr.onreadystatechange = function() {         if(hr.readystate == 4 && hr.status == 200) {             var return_data = hr.responsetext;             document.getelementbyid("status").innerhtml = return_data;         }     }     // send data php now... , wait response update status div     hr.send(vars); // execute request     /*window.open(apri, "", stile);*/     document.getelementbyid("status").innerhtml = "processing..."; } </script>  </head> <body>     <div class="container">         <center><h1>add orders:</h1></center>         <form class="form-inline"  name="ordine">             <div class="form-group" id="prova">                 <label for="buyers">id_buyers:</label>                 <input type="text" class="form-control" placeholder="enter idbuyers" id="id_buyers">             </div>              <div class="form-group" id="prova">                 <input type="submit" id="bottone"  value="show" onclick="ajax_post('sperem.php')"/>             </div>          </form>         <br><div id="status"></div>      </div> </body> </html> 

this php page:

<?php     $dato = $_post['postid'];     echo($dato); ?> 

change from

input type="submit"  

to

input type="button" 

then can data have given in textbox.

the problem here form submitting when run on browser, if want run ajax need run page out submitting/reloading.

hope helps you.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -