Skip to content Skip to sidebar Skip to footer

Unable To Post Json Data To A Remote Server Using Phonegap And Ajax Call

I am trying to send a json data from a javascript function running on a mobile data(phonegap framework) to a remote server. The code looks like below I have researched that the sa

Solution 1:

Check <meta> tag with http-equiv="Content-Security-Policy" parameter in index.html file. Make appropriate(whitelist your domain) changes.

This may help "No Content-Security-Policy meta tag found." error in my phonegap application

Solution 2:

If its php add this to the begining of the server side script to avoid the same origin policy message.

if (isset($_SERVER['HTTP_ORIGIN'])) {
     header("Access-Control-Allow-Origin: *");
     header('Access-Control-Allow-Credentials: true');    
     header("Access-Control-Allow-Methods: GET, POST, OPTIONS"); 
     }   

     if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
     header("Access-Control-Allow-Methods: GET, POST, OPTIONS");         
     if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
     header("Access-Control-Allow-Headers:{$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
     exit(0);
     }

Post a Comment for "Unable To Post Json Data To A Remote Server Using Phonegap And Ajax Call"