class PhotoUploadFormHandler(webapp2.RequestHandler):
def get(self):
# upload_url = blobstore.create_upload_url('/upload_photo')
# The method must be "POST" and enctype must be set to "multipart/form-data".
self.response.out.write('''<html><body>
<form id="imgform" action="none" method="POST" enctype="multipart/form-data">
Name: <input type="text" name="name"/ value="{{ user.name }}" > <br/>
Upload File : <input type="file" name="file1"><br>
<h7 id="create_upload_url">
</h7>
<input type="button" id="submitbutton" value="Submit">
</form>
<div id="output"></div>
</body>
<script type="text/javascript" src="js/zepto.js" > </script>
<script type="text/javascript">
// $('#submitbutton').submit( function(){
$('#submitbutton').live("click",function(){
console.log("submitbutton");
// $('#upload_file').submit();
$('#create_upload_url').load('/create_upload_url', function() {
var create_upload_url=$('#create_upload_url').text();
$('#imgform').attr('action', create_upload_url);
// We serialize the post form, this grabs all the post values in the form.
var info = $(this).closest('form').serialize();
console.log(info);
console.log(create_upload_url);
$.post(create_upload_url, info, function(data) {
// We now pop the output inside the #output DIV.
$("#output").html(data);
});
console.log('Load was performed.'+ create_upload_url );return true;
});
});
</script>
</html>
''')
我从一个工作表单开始,其中上传 url 来自应用程序
但是这与后退按钮有问题
然后我尝试使用 ajax 动态获取 url
虽然我确实得到了典型的 url 并重定向 get_uploads 函数现在返回 0
这是正确的方法吗?