我遇到問題使用.get調用通過頁面加載或按鈕按下更新元素。jQuery獲取函數無意中返回整個網頁
代碼...
$(document).ready(function() {
//updateVariable();
$('#dannychoolink').html('<?php dannyChoo()?>');
$('.danny-choo').attr('target', '_blank');
});
$('#clicky').mouseenter(function() {
$('#dannychoolink').html('Click for a Random DannyChoo.com Article');
}).click(function() {
updateVariable();
$('#dannychoolink').html('YA!');
//$('#dannychoolink').html('<?php dannyChoo()?>');
//$('.danny-choo').attr('target', '_blank');
});
function updateVariable() {
$.get('random.php',
function(output){
$('#dannychoolink').html(output);
$('.danny-choo').attr('target', '_blank');
}
);
};
updateVariable()
調用random.php
功能保持其回聲數據庫條目這樣一個功能:
<a href="http://www.dannychoo.com/post/en/26568/Nendoroid+Moekana.html" class="danny-choo">Nendoroid Moekana</a>
的想法是要加載的隨機條目(這是在函數內完成的)在頁面加載和點擊。
這完美地工作在我的主頁上(http://www.danielbough.com),但不能按預期在單獨的文章上工作(updateVariable函數實際返回一個與個別文章頁面完全相同的html頁面 - 如果這是有道理的。)任何頁面瓦特/一篇文章它(例如http://www.danielbough.com/articles/fun-with-jquery-and-ajax。)
每頁都建有瓦特/單個文件。在 '主頁' 是
- header.file
- navigation.file(在dannychoolink和clicky元素
居住在這裏) - homepage.file
- footer.file
個人文章如下:
- header.file
- navigation.file(在dannychoolink和clicky元素
居住在這裏) - view.file
- footer.file
我想我可能有一些不匹配的標籤視圖。檔案,但沒有任何我能看到的。
我不得不在我的document.ready函數中調用updateVariable()
調用,因爲它會一直加載,直到頁面崩潰。
JavaConsole顯示'Uncaught SyntaxError: Unexpected token < '
當單個文章頁面加載或當我點擊'clicky'元素。我無法確定爲什麼。
請注意,Google+和Twitter調用也在view.file中。我在測試時刪除了它們,但它沒有任何影響。
UPDATE 的'Uncaught SyntaxError: Unexpected token < '
錯誤是由ckeditor.js和谷歌jquery.min.js造成的。我已經將Google js庫更新爲1.7.2的「完整」版本,並刪除了ckeditor.js以進行測試。 Java錯誤消失了,但get函數的問題仍然存在。
保羅 - 你完全正確。實際上,我也得出了這個結論(當我將mod_rewrite規則帶出圖片時)。感謝您的快速回復 - 「學習困難的方式」會停止嗎?! ;) – 2012-08-03 00:23:22
很高興你能弄清楚。不,從來沒有,哈哈。 – 2012-08-03 00:25:49