在php中传递ajax response(json)数据

时间:2014-07-13 16:32:36

标签: mysql ajax json database

所以,我被困在这里,感觉好像在敲我的脑袋 我的问题是我通过ajax查询数据库并以json形式返回其响应。现在我以javascript变量的形式得到了这个响应,但我想将它传递给php变量以供进一步使用 我怎么能这样做?

function getJson(url){
        return JSON.parse($.ajax({
            type:'GET',
            url: url,
            dataType:'json',
            global:false,
            async:false,
            success: function(data){
                return data;
            }
        }).responseText);
    }

这里我如何将数据传递给php?

1 个答案:

答案 0 :(得分:0)

FIrstly I gave you -1 for not learning the basics!
- You can send client values to server (php) as querystring 
  example: /server_link?json=JSON_VAL
  (not recommended for whole json string) 

- Send it as post body (look for jquery ajax post) and parse it with php json library.
- if you have just single level json ({name:'John', sname:'Smith)} you can send it to php server(as mentioned before ajax post) and read as request variable in php ($_POST, $_...).

As I never programmed in php you'll have to do it you're self.

再次:学习基础知识(客户端,服务器端,发布,获取,......)。