cordova - AngularJS and Phonegap Cross Origin Access -
recently created phonegap app mobile devices, using angularjs javascript framework.
i have php backend serving restful json data, build in laravel php framework.
the phonegap app requests data php server $http service in angularjs, , works on mobile phone.
now wanted make phonegap app available on website temporarily instead of in app. moved phonegap project webserver, here doesnt work @ all. these errors when trying use webapp in own browser.
"origin http://somewebsite.com not allowed access-control-allow-origin.".
i tried add config parameters angularjs such as:
delete $httpprovider.defaults.headers.common['x-requested-with'];
but nothing seems help.
i find kinda weird worked phonegap app on phone , in iphone emulator, doesnt work on new webserver domain.
anyone know do?
the safest way use jsonp. in laravel like:
response::json(array('name' => 'steve', 'state' => 'ca'))->setcallback(input::get('callback'));
however if want access open/public, try adding public/.htaccess file
header set access-control-allow-headers: "accept,origin,content-type,x-requested-with" header set access-control-allow-methods "get,put,post,delete,options" header set access-control-allow-credentials: "true" header set access-control-allow-origin "*"
Comments
Post a Comment