haw*_*ett 16 jquery google-app-engine ajaxform
我在AjaxForm文件上传和应用程序引擎blobstore方面遇到了一些困难.我怀疑难度是因为blobstore上传处理程序(blobstore_handlers.BlobstoreUploadHandler的子类)要求重定向响应,而不是返回任何内容,但我不确定.我期待得到一个XML文档,它似乎按预期到达浏览器,但我无法掌握它 - 详情如下.
我的app引擎blobstore上传处理程序如下 -
class UploadHandler(blobstore_handlers.BlobstoreUploadHandler):
def post(self):
upload_files = self.get_uploads('file') # 'file' is file upload field in the form
blob_info = upload_files[0]
entity_key = self.request.get("entityKey")
// Update a datastore entity with the blobkey (not shown)
// redirect to the uri for the updated entity
self.redirect('%s.xml' % entity_key)
Run Code Online (Sandbox Code Playgroud)
最后的重定向是我的应用程序中的uri,它返回一个xml文档.查看服务器输出,没有迹象表明出现任何问题 - 重定向已得到服务,并且按预期返回xml文档,并使用正确的mime类型 - 因此表单提交看起来很好,服务器对该提交的响应看起来很好好.
我的客户端代码使用ajaxForm看起来如下(对不起它有点迟钝,我不认为问题在这里) -
// Create the form
var dialogForm = $("<form method='POST' enctype='multipart/form-data'>")
.append("<span>Upload File: </span><input type='file' name='file'/><br>")
.append("<input type='hidden' name='entityKey' value='" + entityKey + "'/>")
.append("<input type='hidden' name='entityField' value='image'/>")
.append("<input type='button' value='Wait...' disabled='disabled'/>");;
dialogForm.ajaxForm();
// Turn the form button into a nice jQuery UI button and add a click handler
$("input[type=button]", dialogForm[0]).button()
.click(function() {
log.info("Posting to : " + dialogForm.attr('action'));
dialogForm.ajaxSubmit({
success: function(responseText, statusText, xhr, $form) {
log.info("Response: " + responseText + ", statusText: " + statusText + ", xhr: " + goog.debug.expose(xhr) + ", form:" + goog.debug.expose($form));
}
});
});
Run Code Online (Sandbox Code Playgroud)
之后我在表单上设置'action'(并启用按钮) -
$.get('/blob_upload_url', function(data) {
dialogForm.attr("action", data);
$("input[type=button]", dialogForm[0]).attr("value", "Upload").button("option", "disabled", false);
};
Run Code Online (Sandbox Code Playgroud)
我在那里使用了一个小的谷歌闭包来记录和暴露对象.一切看起来都很好 - 正如预期的那样,它正确地发布到服务器,并调用成功函数.如果我在Chrome开发工具中观看文档结构,我可以看到正在简单创建iFrame来处理文件上传和响应.
问题是我从来没有在响应中获取xml文档.日志输出如下 -
[ 18.642s] [Panel] Response: null, statusText: success, xhr: 0 = [object HTMLFormElement]
length = 1
selector =
jquery = 1.4.2, form:0 = [object HTMLFormElement]
length = 1
selector =
jquery = 1.4.2
Resource interpreted as document but transferred with MIME type application/xml [ABCdefGH]
Run Code Online (Sandbox Code Playgroud)
关于mime类型的chrome的投诉可能是超级相关的,但我没有建立连接:) - 至少它意味着它在某些时候获得了xml文档.在Chrome资源视图中,您可以看到POST,并且响应是302重定向,然后是后续的GET请求 - 标题看起来很好 -
Request URL:http://localhost:8081/_ah/upload/ABCdefGH
Request Method:GET
Status Code:200 OK
Request Headers
Referer:http://localhost:8081/
User-Agent:Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4
Response Headers
Cache-Control:no-cache
Content-Length:2325
Content-Type:application/xml
Date:Sun, 20 Jun 2010 20:47:39 GMT
Expires:Fri, 01 Jan 1990 00:00:00 GMT
Server:Development/1.0
Run Code Online (Sandbox Code Playgroud)
Chrome资源视图不会向我显示该文档的内容(只是空白),但firefox确实没有,xml文档看起来很好.Firefox给出了相同的最终结果 - 对于ajaxSubmit()responseText,为null.
我想我只是在某个地方有一个大脑褪色,但它真的让我难过.获取该xml文档的任何指针都会很棒 - 干杯,
科林
| 归档时间: |
|
| 查看次数: |
2410 次 |
| 最近记录: |