Javascript 在视图上使用ajaxForm插件本身就是AJAX响应
我正在为我的站点构建一个消息传递系统。邮箱是扁平的,即访问收件箱或发送新邮件不会移动到其他页面,它只是切换divs。当用户单击消息时,AJAX调用将用所选线程替换inbox div。在thread视图中,有一个用于回复消息的表单 有几个问题:Javascript 在视图上使用ajaxForm插件本身就是AJAX响应,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我正在为我的站点构建一个消息传递系统。邮箱是扁平的,即访问收件箱或发送新邮件不会移动到其他页面,它只是切换divs。当用户单击消息时,AJAX调用将用所选线程替换inbox div。在thread视图中,有一个用于回复消息的表单 有几个问题: 在这个thread_视图中,它向嵌套在整个mailbox div中的div发送AJAX响应,我无法访问它之外的文档对象。因此,我不能在这个视图之外操作div,比如在发送和成功消息之前接收AJAX的div。我认为这可以通过某种.load()来实现,尽管我不确
// compose a message function
$('#send_message').on("click", function(e) {
var send_message_options = {
type: 'post',
url: "/users/new_message",
beforeSend: function() {
//Display a loading message while waiting for the ajax call to complete
$('#message').html("Sending message...");
},
// Hide form and display results
success: function(response) {
$('#message').html(response);
}
};
$('#message_form').ajaxForm(send_message_options);
});
$('#reply_in_thread').on("submit", function(e) {
e.preventDefault();
console.log("trying for reply");
var reply_options = {
type: 'post',
url: "/users/reply",
beforeSend: function() {
//Display a loading message while waiting for the ajax call to complete
$('#reply_message').html("Sending message...");
},
// Hide form and display results
success: function(response) {
$('#reply_message').html(response);
}
};
$('#reply_in_thread').ajaxForm(reply_options);
});
我不知道为什么ajaxForm()插件失败了,但是jquery$.post成功了。代码如下所示:
$('#reply_in_thread').on("submit", function(e) {
e.preventDefault();
var data = $(this).serialize();
$.post('/users/reply',data,function(response){
$('#reply_message').html(response);
})
});