Link to home
Start Free TrialLog in
Avatar of DavidInLove
DavidInLoveFlag for France

asked on

How to do a AJAX query in php

Hey,

I am doing a website http://www.thecacaocafe.com

I do a JQUERY script.

Can some one tell me how to do a simple AJAX query please in JQUERY to get data from my
data.php?

Thanks  David
SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of DavidInLove

ASKER

Thank you,

I have tested this on my website and after one hour
looking for corrections I've managed to have a AJAX GET and POST
THANKS.
The problem with the code I find in books internet... I must always correct something
and loose time.

http://www.thecacaocafe.com/sample_code/ajax/Q_ajax_20140130.html

my comment

With the  link  http://api.jquery.com/jquery.ajax/ I found an example
which fails:


$.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})
  .done(function( msg ) {
    alert( "Data Saved: " + msg );
  });


(
it seems the correct code is

 $.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" },
  success: function(data, textStatus, jqXHR)
    {
        alert(data);
    }
});

After 1 hour struggling I've managed to correct the sample code

 
)

but thanks to it I've been able to correct
the source code a little
$.get("data.php,  => $.get("data.php",
and in the second method you ommited
 data: { param1:"value1A", param2:123456 },

$.ajax({
    method: "GET", // or POST
    url: "data.php",
    success: function(data_or_message_from_data_dot_php) {
       alert( data_or_message_from_data_dot_php );
    }
})

=>

$.ajax({
    method: "GET", // or POST
    url: "data.php",
       data: { param1:"value1A", param2:123456 },
    success: function(data_or_message_from_data_dot_php) {
       alert( data_or_message_from_data_dot_php );
    }
      })