我写了一个CMS它使用PHP函数json_en code到一些数据,通过Ajax请求发回。
I've written a CMS which uses the PHP function json_encode to send some data back via an Ajax Request.
不幸的是,我试图将其装载到这是运行PHP版本5.1的服务器,则json_en code PHP函数不能用于PHP版本5.2.0之前。
Unfortunately, I'm trying to load it onto a server which is running PHP version 5.1, the json_encode PHP function is not available on versions of PHP before 5.2.0.
有谁知道的方式来连接codeA PH数组作为JSON不使用内置json_en code函数?
Does anyone know of a way to encode a PH array as JSON without using the inbuilt json_encode function?
修改
我用佩卡的功能,但现在我发现按预期jQuery将无法解析的结果。即使萤火虫显示JSON传回通过。我的萤火窗口如下所示:
I've used Pekka's function, but now I find JQuery won't parse the result as expected. Even though Firebug shows JSON being passed back through. My firebug window looks like this:
和我的jQuery的是这样的:
and my jquery looks like this:
$.ajax({
type: "GET",
url: "includes/function/add_users.php",
data: str,
dataType: 'json',
cache: false,
beforeSend: function(html){
$('#editbox').html('<img class="preloader" src="images/ajax-loader.gif"/>');
},
success: function(html){
fields = html;
$('#div1').html(fields['username']);
$('#div2').html(fields['fname']);
不过的div:#DIV1和#DIV2不会加载正确的数据。
But the divs : #div1 and #div2 will not load the correct data.
为什么?
推荐答案
的用户贡献的注释的 json_en code 有许多的实现。在粗略地看一眼,这个看起来最好的我。
The User Contributed Notes to json_encode have a number of implementations. On a cursory glance, this one looks the best to me.
如果你有机会到PECL,我会使用扩展名@Artefacto建议。
If you have access to PECL, I would use the extension as @Artefacto recommends.
相关推荐
最新文章