【发布时间】:2013-11-22 02:19:40
【问题描述】:
我需要能够在不重定向或刷新页面的情况下使用 GWT 进行表单上传,但是我的代码不再重定向,它仍然会刷新并且不会弹出警告框:
public static native void showUploadModal(String title, String hash)/*-{
var target = '/files/" + hash + "/';
$wnd.$("<div></div>")
.html("<form id='form_upload' action='' method='post' enctype='multipart/form-data'><p>Select a file: <input type='file' name='file'/></p><input type='submit' id='form_submit' value='Attach'></form>")
.appendTo("body")
.dialog({
title: title,
modal: true,
width: 400,
hide: "fade",
show: "fade",
buttons: {
"Cancel": function() {
$wnd.$(this).dialog("close");
}
}
});
$wnd.$('#form_submit').submit(function() {
// the script where you handle the form input.
var url = '/files/" + hash + "/';
$wnd.$.ajax({
type: "POST",
url: url,
data: $wnd.$('#form_upload').serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response
}
});
return false; // avoid to execute the actual submit of the form.
});
}-*/;
这段代码可能有什么问题?
【问题讨论】:
-
任何客户端或服务器错误?它会进入这段代码吗?
-
是的,点击按钮时调用该方法。它基本上显示了一个模式对话框,然后呈现表单上传
标签: java javascript jquery gwt jsni