AJAX jQuery的PHP返回值

编程入门 行业动态 更新时间:2024-10-22 19:34:03
本文介绍了AJAX jQuery的PHP返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的AJAX和那种很困惑什么是PHP传回的jQuery。 所以,你有一个AJAX功能是这样的:

I am new to AJAX and am kind of confused by what PHP passes back to the jQuery. So you have an AJAX function like this:

$.ajax({ url: '/my/site', data: {action: 'test'}, type: 'post', success: function(output) { alert(output); } });

(我把这个从阿贾克斯另外一个计算器页。)

(I took this from ajax another StackOverflow page.)

但在各种其他资源,他们将有成功的部分是这样的:

But on various other resources they will have the success section look like this:

success: function(data) {functionfoocommandshere}

我只是困惑,是什么决定了这个变量的命名?如果PHP最终都数组:

I am just confused as to what dictates the naming of this variable? If the PHP ultimately echoes an array:

echo $myVar;

我怎样才能得到这个从AJAX?

How can I get this from the AJAX?

推荐答案

这是Ajax的请求获取整个网站。所以,你不会得到任何变量的数据,但在数据参数整个网站。你做了所有回波将在这个参数。如果你想获取一个数组,你应该把它转换成JSON之前。

An Ajax-Requests fetches a whole site. So you'll not get any data in variables, but the whole site in the data-parameter. All echos you made together will be in this parameter. If you want to retrieve an array, you should transform it to json before.

echo json_encode($myArray);

然后就可以用这种方法通过Ajax收到

Then you can receive it via Ajax in this way

$.ajax({ url: '/my/site', data: {action: 'test'}, dataType: 'json', type: 'post', success: function(output) { alert(output); } });

更多推荐

AJAX jQuery的PHP返回值

本文发布于:2023-10-28 18:13:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537390.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   AJAX   jQuery   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!