[英]Using ajaxForm plugin on view that is itself an AJAX response
我正在为我的站点构建消息传递系统。 邮箱是平坦的,即访问收件箱或发送新邮件不会移至另一页,它只是切换div。 当用户单击一条消息时,AJAX调用将用所选线程替换收件箱div。 在线程视图内,有一个表单来回复消息。
一些问题:
从这个thread_view内部,它向嵌套在整个邮箱div中的div发送AJAX响应,我无权访问其外部的文档对象。 因此,我无法在此视图之外操作div,例如接收AJAX beforeSend和Success消息的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);
});
我不能说为什么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);
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.