jQuery的,从PHP收到读JSON变量 [英] Jquery, reading JSON variables received from PHP

查看:102
本文介绍了jQuery的,从PHP收到读JSON变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,如果这是基本的,但我一直在处理搞清楚了这一点一整天,已经得到的地方,我所能做的一切,我需要使用jQuery和CakePHP(不知道CakePHP的事项本或者其任何PHP一样),我想回到从CakePHP的功能,jQuery的一个变量,我读了有关如何做到这一点,喜欢这里:

Sorry if this is basic, but I have been dealing with figuring this out all day and have gotten to where I can do everything I need with Jquery and cakephp (not sure if cakephp matters in this or if its same as any PHP), I want to return a variable from a cakephp function to jquery, I had read about how to do it, like here:

CakePHP的:

$test[ 'mytest'] = $test;
 echo json_encode($test);

和jQuery的:

$.ajax({
  type: 'POST',
  url: 'http://localhost/site1/utilities/ajax_component_call_handler',
  data: {
        component_function: component_function,
        param_array: param_array
        },
        dataType: "json",
  success: function(data) {
   // how do i get back the JSON variables? 
  }
});

我只是无法弄清楚如何获得一个或多个变量回内jQuery的有用的形式,我只是想变,所以我可以做任何其他事情,我一直在寻找什么,我可以通过搜索找到但它不是任何意见使它完全清楚,我..谢谢。

I just can't figure out how to get one or more variables back into usable form within jquery, I just want the variable so I can do whatever else with it, I've been looking at what I can find through searching but its not making it fully clear to me.. thanks for any advice.

推荐答案

您变量数据。

$.ajax({
  type: 'POST',
  url: 'http://localhost/site1/utilities/ajax_component_call_handler',
  data: {
        component_function: component_function,
        param_array: param_array
        },
        dataType: "json",
  success: function(data) {
   // how do i get back the JSON variables? 
      var values = eval( data ); //if you 100 % trust to your sources.
  }
});

这篇关于jQuery的,从PHP收到读JSON变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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