这可能吗?是否有可能通过jQuery.post()有两个成功的回调函数?
一旦我的jQuery.post成功,而不是只有一个成功回调我有两个。
例如
一旦我的形式成功地发布了一个名为“#msg”空div给出的风格和内容和给出一个所谓的“色块”空div样式的数据。
代码到目前为止
$('#form1').submit(function(e)
{
e.preventDefault();
$.ajax({
type: 'POST',
url: 'indextest1.php',
data: $("#form1").serialize(),
success: function(response) {
$('#msg').html("<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and relax.....</div>");
}
});
});
任何帮助或指针将不胜感激。
我试过的东西,并没有工作!
增加另一个回调
$('#form1').submit(function(e)
{
e.preventDefault();
$.ajax({
type: 'POST',
url: 'indextest1.php',
data: $("#form1").serialize(),
success: function(response) {
$('#msg').html("<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and relax</div>");
$("#colour-block").html("<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>bla bla</div>");
}
});
});
使用无极接口
$('#form1').submit(function(e)
{
e.preventDefault();
var ajax = $.ajax({
type : 'POST',
url : 'indextest1.php',
data : $("#form1").serialize()
}).done(function(response) {
$("#msg").html('<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and relax while we go to work on your behalf, we\'ll keep you updated with information on our results and if you have any questions then we welcome your calls or emails on 078675675446 or [email protected]</div>');
$("#colour-block").html('<div style='border: 1px solid black; padding:15px 50px 15px 20px; width:437px; border-radius: 8px; background:#D3EDD3 url(img/accepted_48.png) no-repeat 450px center;'>Now sit back and relax while we go to work on your behalf, we\'ll keep you updated with information on our results and if you have any questions then we welcome your calls or emails on 078675675446 or [email protected]</div>');
});
});
});
难道你不能只是在同一个函数中更新你的第二个div? – Bigood
我不知道,可能。我会怎么做呢?喜欢这个? $('#msg'&&'#color-block')。html我最近才开始使用/学习JavaScript,所以不太确定。我看过api文档,并没有提到这样的事情。 –
哦,我只是添加一个新的线? $('#color-block')。html ............ –