Simple Ajax Program In Php

Active5 years, 11 months ago

AJAX is a developer's dream, because you can: Update a web page without reloading the page Request data from a server - after the page has loaded Receive data from a server - after the page has loaded Send data to a server - in the background.

I'm having a difficult time using AJAX to send an associative array to a php file. There's somethings I'm not understanding clearly. Here's my code to make the array from a form of input tags, but I don't know how to send it and interpret it in php.

Here's my php code:

Ah now everything works. I edited all the code here to make this work.

I also have a div with id=wines . It was another thing I forgot to show. That's where the data is being returned to and displayed without the name however.

docaberle
docaberledocaberle

4 Answers

Simple Ajax Program In Php

Your jQuery code to collect the values is correct, although .serialize() will simplify it.

To retrieve the values in PHP, it's the same as if the form were being submitted normally. They're in $_GET['name'] and $_GET['address1']. theData is just the name of the Javascript variable containing the object, it's not a property name sent to PHP.

BarmarBarmar

Ajax Url Php

466k38 gold badges286 silver badges390 bronze badges

To send data: I'm assuming you want to send the results of your form? To do this, first you're going to need to add a submit button to your page. This should be placed in your form to submit the code.

Ajax Php Tutorial

Second, it looks like you're missing the <div> which you've referenced in the AJAX success response, so you're going to want to add that.

Simple Ajax Examples In Php

meoww-meoww-
1,0492 gold badges15 silver badges28 bronze badges

Try this you have to add button to your form to fire the action:

Osama JetaweOsama JetawePhp vs ajax
2,2255 gold badges18 silver badges36 bronze badges

Sorry I'm on my phone so its a short answer but use serialize

Example

Christian

How To Program In Php

Christian
2,2982 gold badges23 silver badges44 bronze badges

Php Vs Ajax

Not the answer you're looking for? Browse other questions tagged phpjqueryajax or ask your own question.