嵌套的Ajax问题。 如何调试/解决?
关于嵌套的Ajax问题有很多post ,但我无法弄清楚我自己的错误。
我看到的问题是服务器端脚本没有在嵌套的Ajax调用中接收表单值。
在客户端,我得到result2
为null。
嵌套的Ajax代码用// problem
封装。
任何人都可以看到为什么嵌套的Ajax没有收到表单值?
$(document).ready(function(){ $('form').live('submit', function(){ // ... $.ajax({ type: "GET", url: "/cgi-bin/ajax_confirm.pl", contentType: "application/json; charset=utf-8", dataType: "json", // async: false, data: $(this).serialize(), error: function(XMLHttpRequest, textStatus, errorThrown) { $('div#create_result').text("responseText: " + XMLHttpRequest.responseText + ", textStatus: " + textStatus + ", errorThrown: " + errorThrown); $('div#create_result').addClass("error"); alert("Error occured in ajax.js confirm code."); }, success: function(result){ if (result.error) { $('div#create_result').text("result.error: " + result.error); $('div#create_result').addClass("error"); } else { // server side script says everything is okay var users = $.parseJSON(result.users); var owners = $.parseJSON(result.owners); $("#dialog:ui-dialog").dialog("destroy"); $("#dialog-confirm").dialog({ resizable: false, height: 600, modal: true, open: function() { $(this).children('div.dialog-text').replaceWith("Users
" + makeDialogTable(users) + "Owners
" + makeDialogTable(owners)); }, buttons: { Okay: function() { $(this).dialog("close"); // problem $.ajax({ type: "GET", url: "/cgi-bin/ajax.pl", contentType: "application/json; charset=utf-8", dataType: "json", // generate and send parameters to server-side script data: $(this).serialize(), // script call was *not* successful error: function(XMLHttpRequest, textStatus, errorThrown) { $('div#create_result').text("responseText: " + XMLHttpRequest.responseText + ", textStatus: " + textStatus + ", errorThrown: " + errorThrown); $('div#create_result').addClass("error"); }, success: function(result2){ if (result2.error) { // script returned error $('div#create_result').text("result2.error: " + result2.error); $('div#create_result').addClass("error"); } else { // perl script says everything is okay $('div#create_result').text("result2.success: " + result.success + ", result2.id: " + result.id); $('div#create_result').addClass("success"); } //else } // success }); // ajax } else { // if (is_okay) { ... $('div#create_result').text("Fill out the form to create an activity"); $('div#create_result').addClass("error"); } // else }, // Okay // problem Cancel: function() { is_okay = 0; $(this).dialog("close"); } } // buttons }); // dialog } //else } // success }); // ajax // ...
更新这里是HTML,如图所示
dialog text goes here
ID Title Owner Begin Date End Date Type