I enter "Bai" in the search box to automatically prompt "Baidu" and "Baidu image",
Click on the corresponding tag to enter the corresponding website (such as click "Baidu", open http://baidu.com), html+js should be realized, now want to use the way the array of data written in PHP, this How to write Ah, that is, this paragraph
var mockdata=[{name: ' Baidu ', Link: ' http://www.baidu.com '},{name: ' Baidu image ', Link: ' http://image.baidu.com '}]
How to write in PHP and be called
<title>How to query an array</title>
Please enter what you want to search for
Reply to discussion (solution)
$ar = Array ( ' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), Array (' name ' = ' Baidu ', ' Link ' = ' http://www.baidu.com '), Array (' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), $s = Json_ Encode ($ar); echo "var mockdata = $s;";
$ar = Array ( ' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), Array (' name ' = ' Baidu ', ' Link ' = ' http://www.baidu.com '), Array (' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), $s = Json_ Encode ($ar); echo "var mockdata = $s;";
No, No. Cannot invoke
mockdata.php
' Baidu ', ' link ' = ' http://www.baidu.com ', Array (' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), Array (' name ' = ' Baidu ', ' link ' = ' http://www.baidu.com '), $s = Json_encode ($ar); echo "var mockdata = $s;";? >
Index.html
<title>How to query an array</title>
Please enter what you want to search for
You have enough!
You are advised to consult your teacher to find out the difference between the SRC attribute and the script tag without the SRC attribute!