我正在爲我在學校的項目做一些添加,編輯和刪除操作。添加模塊中的代碼進行得很順利,實際上我添加了幾條記錄。然後,Edit模塊出現了,起初它非常好,使用了添加模塊的類似代碼。但是,當我嘗試嘗試時,編輯模塊中的帖子是空的。
這裏是我的編輯代碼:
$(".careersEdit").click(function() {
var careersTableSelect = encodeURIComponent($("input:radio[name=careersTableSelect]:checked").val());
if (careersTableSelect > 0) {
$(".careersEditForm_load").show();
$(".careersEditForm_error").hide();
$(".careersEditForm").hide();
var dataStringCareersEdit = 'careersTableSelect=' + careersTableSelect;
$.ajax({
type: "POST",
url: "admin/careers/process/careersEditGet.php",
data: dataStringCareersEdit,
beforeSend: function(){
alert(dataStringCareersEdit);
},
success: function() {
setTimeout("", 5000);
fetchResult();
},
error: function() {
alert("Post Error");
}
});
function fetchResult() {
$.ajax({
url: "admin/careers/process/careersEditGet.php",
type: "POST",
dataType: "json",
success: function (result) {
if (result) {
$("input#careersEditPosition").val(result['position']);
$("input#careersEditCompany").val(result['company']);
$("input#careersEditLocation").val(result['location']);
$(".careersEditForm_load").hide();
$(".careersEditForm").show();
}
},
error: function() {
alert("Fetch Error");
}
});
}
} else {
$(".careersEditForm").hide();
$(".careersEditForm_load").hide();
$(".careersEditForm_error").show();
}
});
這裏的careersEditGet.php:
<?php
include('connect.php');
error_reporting(0);
$careersTableSelect = $_POST['careersTableSelect'];
//$careersTableSelect = $careersTableSelect + 1;
//echo $careersTableSelect;
$query = "SELECT * FROM atsdatabase.admincareers WHERE refNum ='" . $careersTableSelect . "' LIMIT 0 , 30";
$runQuery = mysql_query($query);
if (!$runQuery) {
die('Could not enter data: ' . mysql_error());
}
$result = mysql_fetch_row($runQuery);
$array = array(
'position' => "" . $result[1] . "",
'company' => "" . $result[2] . "",
'location' => "" . $result[3] . "",
);
echo json_encode($array);
mysql_close($connection);
>
是,代碼是醜陋/錯/廢話,我很?新的jquery的東西,大約3-4天。對於那些會幫助的人,請糾正我。我想學習這個jQuery ajax的東西。格拉西亞斯
'beforeSend:alert(dataStringCareersEdit),'需要'beforeSend:function(){alert(dataStringCareersEdit)},' – haim770
更改了代碼,謝謝。 ;) –
您是否看到數據提示?像預期的那樣是'dataStringCareersEdit'? – haim770