简体   繁体   English

jQuery ajax函数调用返回值的php脚本?

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

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... 感谢您关注我的问题,希望您能对我有所帮助,因为我不太熟悉JavaScript函数的编写,并且对使用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. 无论如何,我需要一种使用jQuery的ajax调用来异步调用php脚本的方法,该脚本将返回一个值并更新标头元素中的值。

Anyone know of the proper way to go about doing this? 任何人都知道执行此操作的正确方法吗?

jQuery: jQuery的:

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

PHP: 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. 相同的网站LearningJQuery还有很多其他很好的例子。

I'd like to add also: 我还要添加:

  • Visual Jquery 视觉jQuery
  • JSbin to try and practice with jQuery in a browser JSbin尝试在浏览器中使用jQuery
  • 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). Firebug我希望在开发过程中使用Firefox和Firebug Togheter:Firebug添加了控制台和dom,net,检查工具(实际上还有很多)。
  • jQuery enlightement that is a good and very cheap e-book I enjoyed a lot jQuery启发 ,这是一本很好而且非常便宜的电子书,我非常喜欢
  • Lot of tutorials from the jQuery official documentation with a big list of other resources. jQuery官方文档中的许多教程 ,以及大量其他资源。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM