How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
I'm trying send some AJAX(not Jquery AJAX) parameter to a server with HTML form values and store it a database. But it doesn't work correctly. When i hit the Let's start button i have got my error message Here is my code....
Creating a new account...
You should type your name Missing username @ Missing email Missing Password Repeat Password
The JAVASCRIPT code
function sendinginfomation(){ if(window.ActiveXObject){ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }else{ xmlhttp = new XMLHttpRequest(); } var fullname = document.getElementById('namefull').value; var user_n = document.getElementById('nameuser').value; var email = document.getElementById('email').value; var user_p = document.getElementById('pass').value; xmlhttp.open("GET",'php/signup.php?w='+fullname+"&n_p="+user_n+"&tv="+email+"&q="+user_p,true); xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState ==4){ $("#loader").fadeOut(300); document.getElementById('AJAXsignup').innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); }
The PHP code
$fullname = $_GET['w']; $username = $_GET['n_p']; $email = $_GET['tv']; $password = $_GET['q']; $server = "localhost"; $username = "root"; try{ $conn = new PDO("mysql:host=$server;dbname=reg_mem",$username); $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO mem_info(Full_name,User_name,Email,Password) VALUES($fullname,$username,$email,$password)"; $conn->exec($sql); echo "The infomation sent sunncessfully."; }catch(PDOException $e){ echo "The infomation unable to send right now"; }
Answer by Shailesh Katarmal for How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
If you want to send information with the GET method, add the information to the URL:
xhttp.open("GET", "filename.php?fname=value&lname=value", true); xhttp.send();
To POST data like an HTML form, add an HTTP header with setRequestHeader(). Specify the data you want to send in the send() method:
xhttp.open("POST", "filename.php", true); xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhttp.send("fname=value&lname=value");
Refer this link for more details
Answer by Dr.Blamo for How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
Use Jquery ajax for send var to the PHP page.
$.ajax({ type: "GET", (or POST) url: "code.php", data: { fullname, user_n, email }, cache: false, success: function(){ } }); });
Answer by Makwana Ketan for How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
Just change this line from HTML.
To
Answer by jitendra parmar for How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
You just need to change your onclick="validate()"
to onclick="sendinginfomation();"
OR you can call 2 function on click like onclick="sendinginfomation();validate();"
Answer by itssajan for How to send parameter with AJAX(not Jquery AJAX) and receive it with PHP
Assuming that your validate()
is working correctly and the sendinginfomation()
is called from within the validate()
function I made a working copy of your code. I found an error in $("#loader").fadeOut(300);
. If you havn't included jQuery
you cant call fadeOut()
. But if you have already included jQuery
there is no need for javascript function, you can use the jQuery ajax itself.
Other than this your code is working fine.
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment