weixin_33670713 2017-07-26 01:12 采纳率: 0%
浏览 23

将复杂的文本传递给JQuery

I have ran into a strange behavior of passing JSON from PHP to jQuery.

I have some articles (Drupal CMS articles) and I need to push them into the environment. First solution worked, while the articles was pushed directly by PHP on page load. But as my work works with more than one CMS, it takes too much time to load them all, so I need to use ajax to load one specific project at time.

now, jquery looks like this:

function doLoadArticles() {

for (var i = 0; i< projectdata[1].length; i++){
 $.ajax({
         data: {ip:projectdata[0]["ip"], login:projectdata[0]["login"], pass:projectdata[0]["pass"], db:projectdata[0]["db"], datatype:projectdata[1][i], aj:"aj", fc:"doLoadArticles"},
         type: "post",
         url: "dataFunnel.php",
         success: function(data){
           console.log(data);
           //console.log(jQuery.parseJSON( data )) ;

         }


         });  

}

}

Then, on PHP side is this code:

function doLoadArticles(){

   $projdata;

  $conn = new mysqli($_POST['ip'], $_POST['login'], $_POST['pass'], $_POST['db']);
     // Check connection
     if ($conn->connect_error) {
     die("<div style='position:absolute; top:0;left:0; background:white;'>Connection failed: " . $conn->connect_error." <br><br>Plese try reload the page</div>");
     break;
     }
    else{}


     $sql = "Select node_revision.title, node_revision.nid, node.language, field_revision_body.body_value, field_revision_body.bundle, node_revision.timestamp  
      from field_revision_body 
      LEFT JOIN node_revision ON field_revision_body.revision_id=node_revision.vid 
      LEFT JOIN node ON field_revision_body.revision_id=node.vid 
      where field_revision_body.bundle='".$_POST['datatype']."' AND node_revision.status=1 AND node.language='cs' 
      ORDER BY field_revision_body.revision_id DESC LIMIT 10";
      $result = $conn->query($sql);

       if ($result->num_rows > 0) {
          // error_log("true"); 
         // output data of each row
            $j =0;
          while($row_a = $result->fetch_assoc()) {    


        $projdata[$j]["title"] = $row_a["title"] ;           
        $projdata[$j]["timestamp"] = $row_a["timestamp"] ;
        $projdata[$j]["bundle"] = $row_a["bundle"] ;
        $projdata[$j]["body_value"] = $row_a["body_value"];
        $projdata[$j]["nid"] = $row_a["nid"];
        $projdata[$j]["language"] = $row_a["language"];  

            $j++;

            }
      }

      echo json_encode($projdata);


}

The problem is, that the data are there, only the passing itself does not work .. (probably because of some buged conversion?)

if I do

echo print_r($projdata);

enter image description here it will pass the data, but not in usable way (ignore the broken chars, that is another not related problem, the data are thare, that is what matters)

However, as it is clear, I need it in form that I can work with, so I need json. But if I use

echo json_encode($projdata);

it will pass some "broken nothing" enter image description here

So is there any my mistake I am not aware of, or it is really some kind of bug in PHP implementation? (by the way, I run on PHP 5.6 on MS IIS7)

Or any other way possible, how to load data dynamically without the json conversion?

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 这种微信登录授权 谁可以做啊
    • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
    • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
    • ¥15 网络设备配置与管理这个该怎么弄
    • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
    • ¥20 西门子S7-Graph,S7-300,梯形图
    • ¥50 用易语言http 访问不了网页
    • ¥50 safari浏览器fetch提交数据后数据丢失问题
    • ¥15 matlab不知道怎么改,求解答!!
    • ¥15 永磁直线电机的电流环pi调不出来