2011-02-17 54 views
0

我必須在某處做出一些簡單的錯誤,任何幫助表示讚賞。

關聯數組

data_form[name] = value; 

行動

$.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)}); 
    } 

}); 

這就是JSON.stringify數據串

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

然後我PHP文件動作結束

$json = $_GET["json"]; 

獲取它,並具有價值

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

然後嘗試進行解碼,並沒有返回值(使用PHP陣列的foreach等)

$array = json_decode($json, true); 
+0

如果你print_r($ array),你會返回什麼?剛剛在本地測試了你的字符串,它填充數組沒有問題。所以這表明這可能是一個與foreach有關的問題。 – simnom 2011-02-17 13:16:32

+0

@simnom它絕對沒有打印任何東西。 – Forteasics 2011-02-17 13:20:06

回答