我正在为我的网站构建一个消息传递系统。邮箱是平的,即访问收件箱,或发送新邮件不会移动到另一个页面,它只是切换div。当用户单击消息时,AJAX调用将使用所选线程替换收件箱div。在线程视图中,有一个表单来回复消息。
一些问题:
从这个thread_view内部发送一个AJAX响应给嵌套在整个邮箱div中的div,我无权访问它之外的文档对象。所以,我无法操纵此视图之外的div,例如在SendSend和Success消息之前接收AJAX的div。我认为这可能是通过某种.load()实现的,虽然我不确定如何。
我的AJAX没有开火。我正在使用Ajax.Form()插件。我认为这个问题可能与第一个问题有关,但我不能肯定地说。我不确定如何开始对Ajax请求进行故障排除,因为我在控制台中没有出现任何错误。
我想知道这个问题是否与我试图从一个视图发送ajaxRequest的事实有关,这个视图本身就是来自前一个ajaxRequest的响应,即该线程的整个视图是跟随,在与下一个请求相同的js文件中:
// 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);
});
我的新AJAX请求,它什么都不做:
$('#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);
});
答案 0 :(得分:0)
我不知道为什么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);
})
});