我遇到了這個問題,我有一組鏈接,我需要獲取所選的值。我正在使用AJAX獲取我想要的內容。但還有另一種方式嗎?我目前的代碼不適用於其他瀏覽器和IOS設備。反正這是怎麼一回事呢:將動態生成的href標記的值傳遞給file_get_contents
比如我有2個動態生成的鏈接:
Link 1(Value是谷歌)
Link 2(Value是雅虎)
說我點擊了鏈接1。我需要獲得該鏈接的值爲「Google」的值(在我的情況下,我使用title =「Google」),並使用變量$ linkName將該變量傳遞給file_get_contents。所以它看起來像:
file_get_contents("http://domain.com/link_contents/includes/**$linkName**")
file_get_contents("http://domain.com/link_contents/includes/**Google**")
我用笨框架BTW。
截至目前,我有一個工作代碼,並使用AJAX。但是,它只能使用Chrome瀏覽器使用:桌面設備和Android設備。可悲的是,它不適用於IOS設備。據我記得,它幾天前與IOS工作,但突然不是。如果我的AJAX代碼對IOS設備有影響,我也正在研究這個過程。
無論如何。這實際上是我第一次做AJAX,所以我很抱歉我的代碼非常混亂。但是,這是我怎麼做的:
在我的header.php我有FF:
$(document).ready(function(){ var getLink = $('.linkClass'); getLink.each(function(i){ $(this).click(function(){ var linkName = $(this).attr('title'); $.ajax({ url: 'http://domain.com/asset/file_get_contents.php', type: "POST", data: { getFromLinkClass: linkName } }).done(function(result) { $('#divID').html(result); }); }); }); });
在我domain.com/asset/file_get_contents.php文件,
$linkName = $_POST["getFromLinkClass"]; if ($linkName != null) { $links = file_get_contents("http://domain.com/link_contents/includes/$linkName", true); echo $links;
}
最後,在我的index.php我可以只調用HTML結果是
<div id="divID"></div>
正如我所說的,這是工作,但在Chrome只:在桌面上和Android瀏覽器。
任何建議/想法/評論?或者有沒有其他的方式來做到這一點,以便它可以在其他瀏覽器和IOS設備上工作?
=======================
UPDATE:
我改變了我的劇本,不理會我的AJAX代碼,並使用純JavaScript代替。它現在也可以和其他瀏覽器一起使用。
無後也Concat的
$linkName
上面有'的http://'或'的https://',這意味着它們都被視爲相對鏈接。如果您的真實代碼缺乏協議,請添加它並查看它是否修復了您的問題。 –嗨@EdCottrell,我忘了把它添加到我上面的代碼塊。我編輯它。但我真正的代碼包括http://。我的代碼雖然工作。但不在其他瀏覽器和IOS中。 – novice