开发者

jQuery ajax function to call php script which returns a value?

开发者 https://www.devze.com 2022-12-31 14:40 出处:网络
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...

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?


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.


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.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号