我知道之前已经被问了很多次,我已经通过了一堆帖子以及谷歌搜索答案,但我只是想不通...这是我的PHP
$connect = mysql_connect("localhost", $usuario, $password) or die(mysql_error()); $select_db = mysql_select_db($dbname) or die(mysql_error()); //query the database $query = mysql_query("SELECT css_id, body FROM content"); //loop through and return results for ($x = 0, $numrows = mysql_num_rows($query); $x < $numrows; $x++) { $row = mysql_fetch_assoc($query); $body[$x] = array("cssID" => $row["css_id"], "inlineContent" => $row["body"]); } //echo JSON to page $response = $_GET["jsoncallback"] . "(" . json_encode($body) . ")"; echo $response;
我的HTML:
Editando
最后我的jQuery:
$(function () { var domID = []; $(".inlineEdit").each(function(){ domID.push(this.id); }); $.getJSON("assets/php/load.php?jsoncallback=?", checkArray); function checkArray(data){ for (var x = 0; x < data.length; x++){//loop through all items in the JSON array for(var j = 0; j < domID.length; j++){//loop through the DOM id's array if(domID[j] === data[x].cssID){ var Element = "$('#" + domID[j] + "')"; Element.text(data[x].inlineContent); } } } } });
我用firebug检查了这个,我确定Element等于$('#linea')和data [x] .inlineContent包含正确的数据,但我一直都是这样:
Element.text不是一个函数
信息...
应该:
var Element = $("#" + domID[j]);
else Element
是一个字符串.