我知道這已被問及很多次,我已經通過一堆帖子以及谷歌搜索的答案,但我只是無法弄清楚......這是我的PHPElement.text不是函數
$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:
<body>
<h2 class="inlineEdit" id="titulo">Editando</h2>
<div id="response"></div>
<ul>
<li class="inlineEdit" id="linea">Lorem Ipsum....</li>
</ul>
</body>
,最後我的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我肯定知道元素等於$( '#LINEA')和數據[X] .inlineContent包含正確的數據,但我不斷收到相同:
Element.text不是一個函數
消息...
由於不能相信我沒看到... – Tsundoku 2009-11-14 04:49:44
@Proxify:這是一個典型的開發者的「黑洞」。有時你只需要將其從某人或SO:P中反彈出來 – 2009-11-14 04:53:12