[英]Jquery Ajax Typo3 Problem - loads homepage
我有以下問題:
我在Typo3(... / index.php?id = 18)的頁面中添加了以下代碼。 (內容元素的內容類型是純html(特殊-> html)。)
<select name="testvariable" id="testvariable">
<option value="1">1</option>
<option value="2">2</option>
</select>
<div id="testformsuccess"></div>
當我調用以下Javascript時,一切正常:
$("#testvariable").change(function(){
if ($('#testvariable').val() == '1') {
$("#testformsuccess").html('1');
}
if ($('#testvariable').val() == '2') {
$("#testformsuccess").html('2');
}
return false;
});
但是,當我嘗試進行Ajax調用時,將立即加載typo3-項目的hompepage,而不是目標div“ testformsuccess”內部的Ajax響應。 這是mey Ajax代碼:
$("#testvariable").change(function(){
$('#testformsuccess').html('');
$.post("../../php/formtest.php", $("#testvariable").serialize(), function(response) {
$('#testformsuccess').html(response);
});
return false;
});
我的PHP是:
<?php
echo "Hello";
?>
我已經發現原因似乎是響應被發送回的頁面ID。 但是我不知道如何解決...
有人知道解決方案嗎?
提前非常感謝您!
jQuery函數$.post()
需要一個有效的URL作為第一個參數(請參閱API文檔 )。 假定腳本位於您的Web實例的根目錄中,請嘗試按以下方式請求PHP腳本:
$.post("/formtest.php", ...);
或: $.post("http://example.com/formtest.php", ...);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.