我在下面通過運行getGrades
函數調用此代碼。使用jQuery將數據加載到字段中AJAX
function getGrades(grading_company) {
// Set file to get results from..
var loadUrl = "ajax_files/get_grades.php";
// Set data string
var dataString = 'gc_id=' + grading_company;
// Set the callback function to run on success
var callback = showGradesBox;
// Run the AJAX request
runAjax(loadUrl, dataString, callback);
}
function showGradesBox(response) {
// Load data into grade field
// Hide condition fields
jQuery('#condition').hide();
jQuery('#condition_text').hide();
// Show grade fields
jQuery('#grade_wrapper').show();
jQuery('#grade_text_wrapper').show();
}
function runAjax(loadUrl, dataString, callback) {
jQuery.ajax({
type: 'GET',
url: loadUrl,
data: dataString,
dataType: 'html',
error: ajaxError,
success: function(response) {
callback(response);
}
});
}
現在你可以看到我傳遞Ajax響應數據的showGradesBox
功能;但是我現在不知道如何將它加載到現場。
我見過使用的例子,但似乎你必須一次性使用這個URL;我遇到的唯一可能使用的唯一其他功能是.html()
;但它的描述聽起來不對!!
get_grades.php返回的是什麼? – mplungjan