Question

I am trying to use ajax.form.js to upload image since form is not compatible with the filetransfer of phonegap.

The javascript

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

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

                } 
            }); 

The 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;

It uploads on html local browser but gives this error: XMLHttpRequest cannot load http://xxxxxxx.com/xxxxxxx. Origin null is not allowed by Access-Control-Allow-Origin.

Tried it on phonegap but it doesn't work but it goes to success checked server no image is uploaded.

Advise on how to do this is very much appreciated and please tell me if I should use another method which will be much better

Was it helpful?

Solution

Have you tried adding the Access-Control-Allow-Origin:* to the header?

Older versions of Phonegap have a blocklist of URLs as well. Try adding your server to the allowed domains.

You can find a guide to add your domain to the whitelist here:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top