我已经写了一个CMS,它使用PHP函数json_encode通过Ajax请求发送一些数据。如何使用json_encode不使用PHP 5.2
不幸的是,我试图将它加载到运行PHP 5.1版本的服务器上,json_encode PHP函数在5.2.0之前版本的PHP上不可用。
有没有人知道一种方法来编码一个PH数组作为JSON,而不使用内置的json_encode函数?
编辑
我用佩卡的功能,但现在我发现按预期jQuery将无法解析的结果。即使Firebug显示JSON被传回。我的萤火虫窗口如下所示:alt text http://www.freeimagehosting.net/uploads/b5a5e5855b.jpg
和我的jQuery看起来是这样的:
$.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不会加载正确的数据。
为什么?
我假设你已经正确关闭了ajax声明?关闭成功功能,然后整体ajax功能? – 2011-03-15 16:31:40
是的,他们被正确关闭,我只是包括相关部分的代码 – Ash 2011-03-16 10:06:49