Poniżej znajduje się skrypt jquery, nad którym pracuję, usunąłem wszystkie jego nieistotne części.Czy można wywołać wywołanie AJAX w innym wywołaniu AJAX w jquery?
Możesz zobaczyć, że istnieje wywołanie ajax, z wyników znajduje się instrukcja if, inne elementy są usuwane, ale w każdym razie captcha jeden jest wybierany z wyniku pierwszego wywołania ajax.
Następnie muszę wykonać drugie wywołanie ajax, to jest mój kłopot, nie dostaję błędów, ale nie wydaje się, aby odpowiedzieć na drugie pytanie, czy brakuje mi czegoś?
<script type="text/javascript">
$(document).ready(function() {
// make ajax call
var dataString = 'comment=' + comment;
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
dataType: "json",
success: function(data) {
//result from 1st ajax call returns "captcha"
if (data.response === 'captcha') {
//a bunch of code is ran
////////////////////////
//then...
$().bind('cbox_closed', function() {
var dataString2 = 'comment=' + comment + '&run=captchagood';
// our nested ajax call
// this is the part that is having trouble =(
$.ajax({
type: "POST",
url: "process.php",
data2: dataString2,
dataType: "json",
success: function(data2) {
if (data2.response === 'captchagood') {
alert('test');
$('div#loader').find('img.load-gif').remove();
$('div#loader').append('<span class="success">Thanks for your comment!</span>');
$('div#loader').hide().fadeIn('slow');
$('span.limit').remove();
$('div#comments').append(data);
$('div#comments div.comment-unapproved:nth-child(1)').hide().slideDown('slow');
$('input#submit-comment').unbind('click').click(function() {
return false;
});
// success append the sanitized-comment to the page
$('#comments').prepend(data.comment);
};
// end captcha status returned
}
});
});
};
return false;
});
});
});
</script>
Czy próbowałeś złapać funkcję wywołania zwrotnego "błąd"? błąd: funkcja (XHR, textStatus) {console.log (XHR); }? Zerknął na prośbę z firebug? – gnarf
To nie jest tak naprawdę * wewnątrz * wywołania AJAX, funkcja 'sukcesu' jest * po * wywołaniu. – Kobi