phonegap上传图像在表单类型文件上

时间:2013-04-22 07:53:49

标签: jquery html cordova ajaxform

我正在尝试使用ajax.form.js上传图片,因为表单与phonegap的文件传输不兼容。

javascript

            $('#sign-up-form').ajaxForm({ 
                //target: '#htmlExampleTarget', 

                success: function(data) { 
                    //alert(data);
                    alert('ok');

                } 
            }); 

php

    $username = $this->input->post('username');

    $config['upload_path'] = './uploads/profile/';
    $config['allowed_types'] = 'gif|jpg|jpeg|png';
    $config['max_size'] = '5024';
    $config['max_width']  = '5024';
    $config['max_height']  = '5024';
    $config['file_name']  = $username;

它在html本地浏览器上传但是出现此错误:XMLHttpRequest无法加载http://xxxxxxx.com/xxxxxxx。 Access-Control-Allow-Origin不允许使用null。

在phonegap上试了但是它不起作用但是成功检查服务器没有上传图像。

非常感谢您对如何做到这一点的建议,请告诉我是否应该使用其他更好的方法

1 个答案:

答案 0 :(得分:1)

您是否尝试过添加 Access-Control-Allow-Origin:*到标题?

旧版本的Phonegap也有一个URL阻止列表。尝试将您的服务器添加到允许的域中。

您可以在此处找到将您的域名添加到白名单的指南:

http://docs.phonegap.com/en/2.6.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

相关问题