我目前正在编写一个用于上传图片的html页面,一旦图片上传,它会使用ajax自动附加到上传部分下方,以便人们可以开始编辑上传的图片。这是我的代码,用于附加图像,图像描述,单选按钮和复选框
$('#thumbnails').append('<div id="imagediv' + str_idnum + '" style="border: 0px solid #aaa;text-align:left;padding:20px;"><div><img src="' + response + '" style="padding:10px; margin-right:20px; border-bottom: 2px solid #ccc;border-left: 2px solid #ccc;border-top: 2px solid #ddd; border-right: 2px solid #ddd;" id="imageid' + str_idnum + '" align="left"/></div><div class="descriptionwrapper" style="border: 0px solid #aaa;"><textarea cols="40" rows="3" id="textarea' + str_idnum + '" onClick="SelectAll(\'textarea' + str_idnum + '\')" align="left" style="resize:none;">Optional description goes here...</textarea><br /><input type="checkbox" style="margin-top:-20px" name="delete" value="Delete" id="delete' + str_idnum + '"/>Delete<br /><input type="radio" name="setcoverpic" value="setcoverpic" id="setcoverpic' + str_idnum + '"/>Make this the front cover of set<br /><br /></div></div><br /><br /><br />');
这里是执行保存,删除,删除全部,功能
的所有按钮的代码 <div id="buttonbardiv">
<div class="fancybuttonwrapper" style="margin-left:100px;"><span class="button"> <span>
<input type="button" class="form_button" id="checkall" value=" Check all"></span> </span> </div>
<div class="fancybuttonwrapper" style="margin-left:316px; "><span class="button"><span>
<input type="button" class="form_button" id="deletecheckedbutton" value=" Delete Checked Items"></span></span> </div>
<div class="fancybuttonwrapper" style="margin-left:500px;"><span class="button"><span>
<input type="button" class="form_button" id="finisheduploadingbutton" value=" Save and Exit">
</span></span> </div>
<div class="fancybuttonwrapper" style="margin-left:460px;"><span class="button"><span>
<input type="button" class="form_button" id="gobackbutton" value=" Go Back">
</span></span> </div>
</div>
<div class="images" id="thumbnails">
</div>
我的问题是,当点击按钮时,我如何调用ajax来执行保存,删除和删除所有功能,谢谢!
答案 0 :(得分:0)
我认为这取决于您的应用程序的工作方式。在RESTful应用程序中,您可以调用它们,例如:
save: POST /things
delete: DELETE /things/1
在服务器上有一个执行请求的控制器。基本上,您必须记住的是将HTTP请求(AJAX)与控制数据库中操作的脚本相关联。