0

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?

2

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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.
Welcome, That's the way I started learning JS and PHP, just please check out that book.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.