+7

Send Data To Php Without Reloading Browser

How can i send data from HTML FORM page to php but without reloading browser. How can i do that?

1/10/2019 11:26:37 AM

Tarek Monowar

13 Answers

New Answer

+10

You need to use ajax to do that

+7

[note] A.synchronous J.avaScript A.nd X.ML

+7

In case you don't need to care about older browsers use simple fetch API: https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch

+3

Yes you can but you need to configure for every browser so it's better to do with jQuery.

+3

Ajax is a technique that USE JS and XML for excange data between client (browser) and server than, it use pure js

+3

Here : (Copy and paste into a text editor cuz it formatted really weird) var request = new XMLHttpRequest();//Create a new XMLHttpRequest request.open("GET","the_url_with_parameters_included",true);//Include your parameters like so : //http://www.example.com/example.php?VAR=VALUE&OTHERVAR=OTHERVALUE //Using echo $_GET["VAR"]; would output "VALUE" request.send();//Send the request request.onreadystatechange = function() {//Call a function when the state changes. if(request.readyState == 4 && request.status == 200) { //Execute this when the request is complete alert(request.responseText);//Alerts the user of the output of the php file } } //That's how you do it!

+3

+2

Adarsh.n. Bidari so, i can't do it with pure js?

+1

Adarsh.n. Bidari Ohh,Thank you bro ❤

+1

KrOW Ohh, Thank you for your useful information 😊

+1

In case users have older browsers use this: If(window.XMLHttpRequest) {var request= new XMLHttpRequest(); //supported in all modern browsers} Else if(window.ActiveXObject) {var request= new ActiveXObject("Microsoft.XMLHTTP"); //For ie 8 and below}

0

thanks Nedjmi

0

Adarsh.n Bidari - exactly what I was going to say. To further explain php required a page reload whereas Ajax uses the DOM to gather and retrieve information to update a page if and when the information changes.