开发者

Retrieving json array with $.ajax GET to php

I must be making some simple error somewhere, any help appreciated.

Associative Array

data_form[name] = value;

Action

$.ajax({
    type:       "GET",
    cache:      false,
    url:        "../pages/ajax/takeaction.php",
    data:       ({ json: JSON.stringify(data_form) }),
    success: function(data) {
        var message = "Your information has been received!";

        $('.element').html(message)
             .hide()
             .fadeIn(1500, function() {                 
                $(this).append("<br/>"+data)});
    }

});

This is what the JSON.stringify data string ends up as

{"action":"register","username":"","email":"","password":"","password2":"","max":"5000000","userfile":""}

Then my php file action

$json = $_GET["json"];

Gets it and has value

{\"action\":\"register\",\"username\":\"\",\"email\":\"\",\"password\":\"\",\"password2\开发者_如何学C":\"\",\"max\":\"5000000\",\"userfile\":\"\"}

Then try to decode and it returns nothing (using php array foreach etc)

   $array = json_decode($json, true);


Do you have both jQuery and Prototype included? If so, take a look at JSON.stringify() array bizarreness with Prototype.js.

On second thought it looks less like that and more like you have magic_quotes_gpc set to On in php.ini.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜