我想有以下的返回結果(search.php
)並將結果張貼在原始頁面(index.php
)中的div中。PHP + jQuery的+ Ajax表單提交相同的頁面
我已經把大部分的代碼放在一起了。它通過單擊提交表單並將其發送到PHP腳本。
我現在需要的是將PHP腳本的結果返回到原始頁面(index.php
)。
這裏是我到目前爲止的代碼:(測試)
function submit() {
$(function() {
var id = "id";
var dataString = 'id=' + id;
$.ajax({
type: "POST",
url: "inc/search.php",
data: dataString,
success: function() {
goToByScroll("result");
$('#result').html("<br><br><br><br><br><br><br><br><br><br><
div class='center'><img src='img/loader.gif' /></div>").hide().fadeIn(2500, function() {
$('#result').html("Finished");
});
}
});
return false;
});
}
我的PHP文件是:
<?php function safe($value)
{
htmlentities($value, ENT_QUOTES, 'utf-8');
return $value;
}
if (isset($_POST['id'])) {
$id = safe($_POST['id']);
echo ($id);
}
elseif (!isset($_POST['id'])) {
header('Location: error?id=notfound');
} ?>
我想有結果從search.php
(在這種情況下, 「ID」)張貼到#result,但我不知道如何:S
這是100%正常工作:)和最好的事情:我只需要複製並粘貼它!非常感謝! – Andrej 2011-04-15 20:09:02
呵呵,我只給你添加了大約六個字符,你只能輸入它們。很高興它解決了 – 2011-04-15 22:53:45