AJAX from Phonegap not working

86 Views Asked by At

This is my code in index.js:

$.ajax({
    type: 'GET',
    data: {registrationdata: registrationDataJson},
    async: false,
    url: 'https://example.com/push_reg',
    success: function(data){
        alert("Your device has been successfully registered for push notifications with device id of: " + data);
    },
    error: function(){
        alert('There was an error registering your device');
    }
});

I have tried it with both async on and async off. I do not get any alert from either success or error. I put a log line first thing where /push_reg routes. If I hit it in a desktop browser it logs but not from the app. I have alert(registrationDataJson); right before this code block (registrationDataJson is a stringified JSON) so I know the data is good. I have alert('after'); directly after this code block that I never hit so I know that it never gets past this block.

2

There are 2 best solutions below

0
On

You might want to elaborate and indicate what error messages code / errors you are seeing. Check your config for setting, etc.

0
On

Please check your config.xml file and make sure that you have these:

<plugin name="cordova-plugin-whitelist" source="npm" spec="1.1.0" />
<allow-navigation href="*" />
<allow-intent href="*" />
<access origin="*" />

<preference name="permissions" value="none"/>