Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中解析json值并显示在表中_Php_Html_Json - Fatal编程技术网

在php中解析json值并显示在表中

在php中解析json值并显示在表中,php,html,json,Php,Html,Json,这是我的html <html> <head> <script src="js/jquery.js"></script> </head> <body> <input type="text" name="query" id="queryBox"> <button id="load_basic" value = "button">search</button><br/> &l

这是我的html

<html>
<head> 
<script src="js/jquery.js"></script>
</head>

<body> 
<input type="text" name="query" id="queryBox">
<button id="load_basic" value = "button">search</button><br/>

<div id="result"></div>
</body>

<script>

    $.ajaxSetup ({
        cache: false
    });
    var ajax_load = "<img src='images/ajax-loader.gif' alt='loading...' />";

    $("#load_basic").click(function(){
    var query = $("#queryBox").val();
    var loadUrl = "http://localhost:8983/solr/collection1/select?q=" + query +"&fl=title&wt=php&indent=true";
    $("#result").html(ajax_load).load(loadUrl);

    });

</script>

</html>
如何解析此json并仅获取标题中的值

<?php
$query = "http://localhost:8983/solr/collection1/select?q=" .  $_GET['q'] ."&fl=title&wt=json&indent=true";
$response = file_get_contents($query);
echo $response;
?>

在JS中,要解析div中的JSON,可以这样做

var myJSON=jQuery.parseJSON(jQuery('#result').text());
var title=myJSON.response.docs[0].title;
console.log(title);
var myJSON=jQuery.parseJSON(jQuery('#result').text());
var title=myJSON.response.docs[0].title;
console.log(title);