jquery$(';#myForm';).ajaxForm(函数()未第二次触发document.ready()
我正在为我的项目使用jquery、backbonejs和下划线js。我想使用ajaxForm和document.ready()上传图像。在productImageView.js上我有jquery$(';#myForm';).ajaxForm(函数()未第二次触发document.ready(),jquery,backbone.js,underscore.js,Jquery,Backbone.js,Underscore.js,我正在为我的项目使用jquery、backbonejs和下划线js。我想使用ajaxForm和document.ready()上传图像。在productImageView.js上我有 define(['jquery', 'underscore', 'backbone', 'text!templates/product/productImageTemplate.html'], function($, _, Backbone, productImageTemplate) { var ProductI
define(['jquery', 'underscore', 'backbone', 'text!templates/product/productImageTemplate.html'], function($, _, Backbone, productImageTemplate) {
var ProductImageView = Backbone.View.extend({
el: $("#page"),
initialize: function() {
this.$el.off();
},
render: function() {
$(function() {
$('#myForm').ajaxForm(function() {
alert("Image uploaded");
});
});
this.$el.html(productImageTemplate);
}
});
return ProductImageView;
});
在productImageTemplate.html上
<form id="myForm" action="upload_image.php" method="post">
<input name="uploadfile" type="file" />
<input type="submit" id="uploadButton" value="Upload" />
第一次上传图像时,一切正常。但第二次访问页面并上传时,document.ready()
不工作
先谢谢你
资源:将放在这个.el.html(productImageTemplate);
在ajaxForm之前
您不需要在此处使用$(function(){
。渲染视图时,DOM应该已经准备好。如果您对此不确定,请将脚本放在
之前,在渲染中对ajax尝试以下操作:
$('#uploadButton').click(function(){
$.post('process_file.php', $('#myForm').serialize());
});
瞧!谢谢你救了我的命。愿上帝保佑你。