I
I
Ilya2016-09-14 17:57:59
Mobile development
Ilya, 2016-09-14 17:57:59

AJAX request to server in Cordova/Phonegap app?

Help me, the bottom line is, I created a cordova application, connected JQuery, now I want to send an AJAX request to my server and return the results from the server. The result is the following

XMLHttpRequest cannot load http://my site. The 'Access-Control-Allow-Origin' header contains multiple values ​​'*, *', but only one is allowed. Origin 'null' is therefore not allowed access.


I read all day long. I did the following
On the server in this file I put the title at the beginning of the file. Here is my ajax request
header('Access-Control-Allow-Origin: *');

$('#login').click(function(){
                    var id=localStorage.userName;
                    alert(id);
                    $.ajax({
                    url:'http://web-candy.ru/new/adm/ajax-app/login.php',
                    type:'POST',
                    data: {'id':id},
                    crossDomain: true,
                   
                    success: function(res) {
                        alert(res);
                       }
                    })
                })


I make the application using HTML / JS / CSS in Sublime Text 3. I run tests in the browser and in the Genimotion emulator. As I understand it, you cannot send requests from local files. Then how to be? Is there a solution, thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nicholas, 2016-09-14
@ACCNCC

https://www.npmjs.com/package/cordova-plugin-whitelist

I
Ilya, 2016-09-14
@ironfrol

Here is what I have in config

<access origin="*" subdomains="true" />
    <allow-navigation href="*"/>
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question