jQuery的AJAX函数来调用PHP脚本返回一个值? [英] jQuery ajax function to call php script which returns a value?

查看:95
本文介绍了jQuery的AJAX函数来调用PHP脚本返回一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您看我的问题,希望你能帮助我为我是一个不精通编写JavaScript功能,是比较新的使用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...

不管怎么说,我需要一种方法来使用jQuery的Ajax调用异步调用PHP脚本将在头元素返回一个值,并更新值。

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.

这篇关于jQuery的AJAX函数来调用PHP脚本返回一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆