Jump to content

How to POST using AJAX?


hola

Recommended Posts

I have a simple form

 

<form name=myForm>

<input type="text" name="username" />

<input type="submit" value=Submit />

</form>

 

<?PHP

if(isset($_POST['submit'])){

$username=$_POST['username'];

$fields = array(username);

$values = array($username);

$db->insert($fields,$values,'customer');

echo "data added";

}

?>

 

I want to insert data to database table using POST method. How do i do that using ajax?

 

 

Link to comment
https://forums.phpfreaks.com/topic/80915-how-to-post-using-ajax/
Share on other sites

  • 4 weeks later...

You might want to consider using the Prototype JavaScript framework. Get it here: http://www.prototypejs.org

 

They also have a guide on using AJAX so read up on that. It will make things a lot easier since you don't need to worry about different browsers using different protocols.

I have a simple form

 

<form name=myForm>

<input type="text" name="username" />

<input type="submit" value=Submit />

</form>

 

<?PHP

if(isset($_POST['submit'])){

$username=$_POST['username'];

$fields = array(username);

$values = array($username);

$db->insert($fields,$values,'customer');

echo "data added";

}

?>

 

I want to insert data to database table using POST method. How do i do that using ajax?

 

 

 

Hi,

 

Making AJAX POST request is very easy if you are aware of simple ajax stuff.

 

    http_request = new XMLHttpRequest(); //XMLHttpRequest method has to be defined to create xmlHttprequest

    http_request.onreadystatechange = function() {s=alertContents(http_request)};

    frmstr='name=priti?age=25&gender=f&job=yes&designation=developer';

    http_request.open('POST', "./tests.php", true);

    http_request.send(frmstr);

 

And if you don't want to use this go for jquery ajax.It is easy and smooth.

 

regards

  • 3 months later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.