PHP json_de code不支持,任何替代方案? [英] PHP json_decode not supported, any alternatives?

查看:161
本文介绍了PHP json_de code不支持,任何替代方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为题规定,我的托管服务提供商不具有json_de code的支持,所以我需要找到一个方法来适应我的code,以达到同样的效果,但不使用JSON,这里是我的code,

as the title specifies, my hosting provider does not have support for json_decode, so I need to find a way to adapt my code to achieve the same effect, but without using JSON, here is my code,

jQuery的:

    var allLocations = [];

    $(".locations").each( function(i, location) {
        // for each location block
        location = $(location);
        var loc = {
            'province' : $("select[data-loc*='province']", location).val(),
            'town' : $("select[data-loc*='town']", location).val()
        };
        allLocations.push( loc );
    });

        //POST the locations information
        $.ajax({
                type: 'POST',
                url: 'locations.php',
                dataType: 'json',
                data: { locations: JSON.stringify(allLocations), uid: uid },
                success: function(data){
                    //alert(data)
                }
        });

PHP:

$json = $_POST['locations']; 
$uid = $_POST['uid']; // $json is a string
$json_array = json_decode($json, true); 

mysql_connect('localhost','user','pass') or die(mysql_error());
mysql_select_db('eskom_products') or die(mysql_error());

//insert the locations into the database
while($json_array as $key){
    $query = mysql_query("INSERT INTO suppliersLocations (supplier_id, province, town) VALUES('".$uid."', '".$key['province']."', '".$key['town']."' ) ") or die(mysql_error());
}

echo $text;

因此​​,大家可以看到,我得到各个位置的省和城市价值,并与它创建一个JSON对象,然后我通过 $送行。AJAX 到PHP文件,但现在因为 json_de code 不工作,我需要尝试并找到解决问题的另一种方式,我想试图传递一个关联数组到PHP文件,但我想看看你的男人的投入将是,如果有可能达不到预期效果的更好的方式。

So as you can see, I am getting the province and town values of each location and creating a JSON object with it, which I then send off via $.ajax to a PHP file, but now since json_decode doesn't work, I need to try and find another way of fixing the problem, I was thinking of trying to pass an associative array to the php file, but I wanted to see what your guy's input would be, and if there might be a better way of achieving the desired result.

感谢名单提前!

推荐答案

看来,它是在被搞乱json_de code中的PHP配置文件中一个不起眼的设置,一旦我关闭它,一切为了工作得很好,感谢名单您的帮助家伙!我将编辑这个答案尽快来描述我是如何得到它的工作。

Seems that it was an obscure setting in the php config file that was messing with json_decode, once I disabled it, everything worked fine, Thanx for all of your help guys! I will edit this answer asap to describe how I got it working.

这篇关于PHP json_de code不支持,任何替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆