json_en code()返回任何结果 [英] json_encode() return nothing

查看:120
本文介绍了json_en code()返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用json_en code()方法解析一个数组,但返回空白的一个PHP脚本

I have a PHP script that parses an array using the json_encode() method but returns blank

PHP的code如下:

The PHP Code is as follows

$companies = $db->getCustomerNames();
print_r($companies)
if (!empty($companies)){
$jsonstring = json_encode($companies);
echo $jsonstring ; 
}
else{
    echo 'false';
}

  • 在$企业被填充,我可以把它打印出来却
  • 我也有一个JavaScript看起来像这样

    I also have a javascript that looks like this

    jQuery.ajax({
    
        type: "GET",
        url: "http://localhost/myscript.php"
        success: function(msg) {
            companies = jQuery.parseJSON(msg);
            //DO OTHER STUFF WITH companies 
        }
    });
    

    • 在PHP脚本连接到数据库,并呼应的JSON恩codeD数组
    • JavaScript的使用AJAX获取数组,所以我可以用它的内容
    • 当我打 HTTP://localhost/myscript.php 得到了一个空白页面
    • 在我的本地服务器上工作正常
    • 在该网页托管在雅虎(不知道这是否有差别)
      • The PHP script connects to a DB and echo the JSON encoded array
      • The Javascript gets the array using AJAX so i can use it's content
      • When I hit http://localhost/myscript.php i get a blank page
      • Works fine on my local server
      • The page is hosted on Yahoo (not sure if it makes a difference)
      • 推荐答案

        尝试使用function_exist,因为在某些服务器上的JSON *函数可以被禁用或PHP配置为不使用它

        Try to use function_exist because on some servers json* functions could be disabled or php is configured to not use it

        这篇关于json_en code()返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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