views:

64

answers:

2

Hello! Thank you for looking at my issue, hopefully you can help me out as I'm an not well versed in writing JavaScript functions and am relatively new to using jQuery...

Anyways, I need a way to use jQuery's ajax call to asynchronously call a php script which will return a value and update the value in a header element.

Anyone know of the proper way to go about doing this?

+3  A: 

jQuery:

$.post('url_to_script',{"anyData": "that is needed"}, function(data){
    $('#headertarget').text('data');
});

PHP:

$anyData = $_POST['anyData'];
function getAnswer ($inp){
    //logic goes here
    return "a string of some sort";
}
echo getAnswer($anyData);
exit;

It will put any text you send back to the client into the heading element.

Rixius
and yes, google is your friend. I also suggerst checking out Javascript: the missing manual. It teaches the basics of Javascript, as well as jQuery.
Rixius
You're the man, thank you very much brother!
Stevie Jenowski
Welcome, That's the way I started learning JS and PHP, just please check out that book.
Rixius
+1  A: 

For the specific subject you said I would go here. The same website LearningJQuery has tons of other nice examples.

I'd like to add also:

  • Visual Jquery
  • JSbin to try and practice with jQuery in a browser
  • Firebug I hope i use Firefox and Firebug togheter during development: Firebug add a console and dom, net, inspection tools (and a lot more actually).
  • jQuery enlightement that is a good and very cheap e-book I enjoyed a lot
  • Lot of tutorials from the jQuery official documentation with a big list of other resources.
microspino