非表示の入力を使用して別のパラメーターを追加しようとしています:
$('#form1').submit(function(){ //listen for submit event
$('<input />').attr('type', 'hidden')
.attr('name', 'id')
.attr('value', id)
.appendTo('#form1');
return true;
});
「id」はグローバル変数です。
私のHTMLフォーム:
<form id="form1" method=POST runat="server" enctype='multipart/form-data' action="/set_image">
<div class="fileButtons">
<input type='file' id="imgInp" name="imgInp" accept="image/*"/>
<input type='button' id='remove' name="remove" value='Remove' />
</div>
<br>
<div class="modal-footer">
<a type="button" class="btn pull-left" data-dismiss="modal">Cancel</a>
<button type="submit" class="btn btn-primary pull-left">OK</button>
</div>
</form>
Google App Engine のログ コンソールを見ると、「id」のみが値を取得していることがわかります。
firebug では、デバッグ中に次のように表示されます。
imgInp
input#imgInp property value = "2.jpg" attribute value = "null"
main.py:
class SetImage(webapp2.RequestHandler):
def post(self):
id = str(self.request.get('id'))
image = str(self.request.get('impInp'))
...
app = webapp2.WSGIApplication([ ('/set_image', SetImage),
('/', MainPage)], debug=True)
ここで投稿を使用しました:
https://stackoverflow.com/a/993897/2653179
編集: 問題は解決しました。SetImage クラスの imgInp 変数のタイプミスでした...