[英]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: 我还要添加:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.