PhoneGap文件上传使用jQuery Ajax [英] PhoneGap File Upload Using jQuery Ajax

查看:122
本文介绍了PhoneGap文件上传使用jQuery Ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发使用PhoneGap的移动应用程序,并想问是否有方法使用jQuery的ajax上传文件到服务器(PHP)。
我使用ajax,因为我想避免从网页重定向(当然,我想重定向到我自己的网页)。
所以,这里是我的一些代码:

$ $ $ $ $ $ ajax({
url:url,
data:$(#myform)。serialize(),
type:post,
dataType:json
});

以下我已经尝试了这些组合,但没有任何效果。有什么想法吗?

$ p $ contentType:false
cache:false
processData:false
contentType: multipart / form-data


解决方案

必须使用PhoneGap的FileTransfer类。



文档和一些示例代码在这里: http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#FileTransfer


I develop mobile app using PhoneGap and wanna ask if there is a way to upload a file to server (php) using jQuery's ajax. I use ajax because I want to avoid redirection from a web page (Of course, I want to redirect to my own page). So, here is some of my code:

$.ajax({
    url: url,
    data: $("#myform").serialize(),
    type: "post",
    dataType: "json"
});

and I've tried these combinations below but nothing works. Any idea ?

contentType: false
cache: false
processData: false
contentType: "multipart/form-data"

解决方案

You'll probably have to use PhoneGap's FileTransfer class.

Documentation and some example code is here: http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#FileTransfer

这篇关于PhoneGap文件上传使用jQuery Ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆