0
對於我的生活,我不明白爲什麼會發生這種情況。數據回來,但無法發佈在jquery ajax
基本上我使用下面的代碼從數據庫中恢復錶行。
var getCposInputs = {
'type': 'viewcpos',
'quoteid': '<?php echo $_GET['id']; ?>'
};
$.ajax({
type: 'POST',
url: '/Applications/Controllers/Quotes/ajax-add-sin.php',
data: getCposInputs,
dataType: 'html',
encode: true
}).done(function(data){
//$('body').html(data);
buildcotable += data;
});
因此,大家可以看到有被註釋掉行取出時給出了詳細的直入體,而不是稍後送出使用JavaScript中的的.html()函數的變量。
,所以該完整的jQuery代碼:
var buildcotable = '';
var buildtrs = $('#formentry15').val();
var coArray = '';
var coArrayNumber = 1;
buildcotable += '<div class="table-responsive">';
buildcotable += '<table class="table table-bordered">';
buildcotable += '<thead>';
buildcotable += '<th class="text-center">Number</th>';
buildcotable += '<th class="text-center">Price</th>';
buildcotable += '<th class="text-center">Installments</th>';
buildcotable += '<th class="text-center">Contact Initials</th>';
buildcotable += '<th class="text-center">Options</th>';
buildcotable += '</thead>';
buildcotable += '<tbody id="jquerypotable">';
//lets do a check and see how many are listed
if(buildtrs != 'TBC'){
var getCposInputs = {
'type': 'viewcpos',
'quoteid': '<?php echo $_GET['id']; ?>'
};
$.ajax({
type: 'POST',
url: '/Applications/Controllers/Quotes/ajax-add-sin.php',
data: getCposInputs,
dataType: 'html',
encode: true
}).done(function(data){
$('body').html(data);
buildcotable += data;
});
} else {
buildcotable += '<tr id="jqueryporow1">';
buildcotable += '<td><input type="hidden" value="No" id="jqueryponumber1" class="form-control">No CPO\'s have been submitted</td>';
buildcotable += '<td><input type="hidden" value="" id="jquerypovalue1" class="form-control"></td>';
buildcotable += '<td class="text-center"><input type="hidden" value="" id="jquerypoinstallments1" class="form-control"></td>';
buildcotable += '<td><input type="hidden" value="" id="jquerypocontactinitials1" class="form-control"></td>';
buildcotable += '<td class="text-center"> </td>';
buildcotable += '</tr>';
}
buildcotable += '</tbody>';
buildcotable += '</table>';
buildcotable += '<p><a href="#" class="btn btn-default btn-block" id="addnewpo">Add New CPO Number</a></p>';
buildcotable += '<p><a href="#" class="btn btn-danger btn-block" id="ubldonepo">Done</a></p>';
buildcotable += '</div>';
$('.ubl-section-7').html(buildcotable);
我知道數據是回來了罰款,因爲當我刪除了$(「身體」)的註釋HTML(數據)。然後顯示信息。
但是,如果試圖把它放入一個變量,它什麼也不做。
爲什麼會發生這種情況的任何想法?
感謝
'完成'處理程序中'data'的值是什麼? –
那麼,你的代碼在ajax請求完成之前呈現。所以基本上,在ajax請求檢索其數據之前,腳本的結束(很可能)已經到達。您需要一個同步解決方法。 – antesoles
@RoryMcCrossan只是普通表信息。沒有什麼特別的,一組tr和td元素,其中包含數據。正如前面提到的,我知道由於在所提及的身體渲染中沒有錯誤。謝謝:) – Robert