Link to home
Start Free TrialLog in
Avatar of Slim81
Slim81Flag for United States of America

asked on

Jquery and $.ajax, how to retrieve data from POST...

Hey Guys and Gals,
I am finally stepping into the world of Ajax and I have a question....  How do I grab values that are returned from a script the javascript POSTed to?

This is what I am trying to do:

I have a 'Promo Code' field and want to check to see if the promo code is valid.  The javascript (JQuery) will post to my script and then send some data back (example: the Promotion Name that is tied to the promo code).

Here is some generic code, check the commented code for my issues...
$.ajax({
  type: "POST",
  url: "some.php",
  data: "name=John&location=Boston",
}).done(function( msg ) { //---- It looks like 'msg' is the returned value from the some.php script.
  alert( "Data Saved: " + msg );

//How do I send 'msg' from the some.php file back to my requesting page?  Should 'msg' be a javascript variable in some.php?
});

Open in new window


Thanks for the help!
SOLUTION
Avatar of haloexpertsexchange
haloexpertsexchange
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
Avatar of Slim81

ASKER

haloexpertsexchange,
Thanks for the reply.

Anything that the browser would display?

In the example I provided (pulled from the JQuery website), they use the variable/parameter of 'msg' in the '.done' function.  Do I have to reference or create 'msg' on the some.php file or am I free to name that variable/parameter whatever I want?

Thanks!
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 Slim81

ASKER

Brilliant.  JQuery has made ajax easy for me to understand.

ajax rocks.

Thanks for your help!