大家好,
有任何的JavaScript功能,甚至在jQuery庫(我想是的,因爲jQuery有JSON庫並能夠序列),做同樣的PHPprint_r()
功能?是否有任何JavaScript函數,或者甚至在與PHP print_r()相同的jQuery庫上?
我一派這個,但我發現只有函數來打印單維或雙維數組。
在此先感謝...
何塞·莫雷拉
編輯:
問:我爲什麼問這個?
答:其實我有一個$.ajax()
呼叫接收的JSON字符串像這樣(數字編輯隱私):
{"sms":{"92255221":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255222":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255223":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255224":{"status":true,"debug":"ok","warnmsg":"SMS Sended!!"},"92255225":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255226":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255227":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"},"92255228":{"status":true,"debug":"ok","warnmsg":"SMS Sended!"}}}
而且我success: function()
我已經somethink這樣的:
success: function(response){
var data = $.parseJSON(response);
img_ok = "<img src=\"http://www.mysite.com/images/icons/icon-ok-16.png\" />";
img_fail = "<img src=\"http://www.mysite.com/images/icons/icon-fail-16.png\" />";
for (i=0;i<=mobilenumbers.length;i++){
var selector = "input.client[value*="+mobilenumbers[i]+"]";
// Remove input checkbox
$(selector).remove();
// Replace by an image
if(data['sms'][mobilenumbers[i]]['status']){
$(selector).filter(function(){return $(this).attr("checked");}).parent().append(img_ok);
}else{
$(selector).filter(function(){return $(this).attr("checked");}).parent().append(img_fail);
}*/
}
但螢火蟲說data['sms'][mobilenumbers[i]]
是未定義的......但奇怪的是,第一個data['sms'][mobilenumbers[i]]['status']
工作正常!
你的bug在這裏我<= mobilenumbers.length;索引從0開始,你試圖閱讀太多的索引。你的代碼也是非常低效的,因爲你繼續查找你已經查找過的東西一次。你是我的全球。當選擇器可以做到這一點時,爲什麼在過濾器中使用函數? – epascarello 2010-07-10 14:46:45
@epascarello我試過了:在我的選擇器上檢查過,但沒有奏效,不問我爲什麼...該呼叫是給錯誤,現在糾正,但沒有成功 – CuSS 2010-07-10 15:06:16
@ALL 問題解決了,PHP返回壞數字,錯誤到'array_merge_recursive()'功能... 感謝所有 – CuSS 2010-07-10 15:38:29