没有图片或jquery的phonegap表单提交

时间:2013-01-22 05:01:39

标签: forms cordova

这就是我在下面的内容,我提交表单的唯一方法是浏览图片 有人可以告诉我如何用按钮提交,最好没有jQuery 我只想提交一份包含文字,没有图片的表格。谢谢!

function browse()
{
    navigator.camera.getPicture(uploadPhoto,
        function(message) { alert('get picture failed'); },
        { 
            quality: 50,
            destinationType: navigator.camera.DestinationType.FILE_URI,
            sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
        }
    );
}

function uploadPhoto(imageURI)
{
    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=imageURI.substr(imageURI.lastIndexOf('/')+1);
    options.mimeType="image/jpeg";

    var params = {};
    params.value1 = "test";
    params.value2 = document.getElementById('file_name').value + "";
}

2 个答案:

答案 0 :(得分:0)

尝试使用普通的HTML表单:

<form action="/post" method="post">
  Input: <input type="text" value="input something"/>
  Submit: <input type="submit" value="Submit"/>
</form>

答案 1 :(得分:0)

我认为你要问的是如何将图像从相机提交到服务器,而无需使用文件输入表单元素,用户必须浏览文件等。

最简单的答案就是不将图像存储为文件,而是将其保存为base64字符串。为此,请将目标类型更改为

destinationType: Camera.DestinationType.DATA_URL

您的成功函数的参数现在将是一个base64字符串,您可以像任何其他字符串一样发送到您的服务器。然后,您需要在服务器端对其进行base64_decode,然后将其写入磁盘。

相关问题