问题
I have a problem with my phonegap project working on blackberry simulator. The version is 10.
When I say phonegap, I haven't used any Cordova features yet but my simple javascript functions are not working in the first place.
I have a button click which invokes a Javascript function. This JS function has a PHP as URL to retrieve data. Following is the function code -
function getAllDetails() {
var myTable = '';
myTable += '<table id="myTable" cellspacing=0 cellpadding=2 border=1>';
myTable += "<tr><td><b>S.No.</b></td><td><b>Full Name</b></td><td><b>DOB</b></td><td><b>Gender</b></td><td><b>Address</b></td><td><b>Image</b></td><td><b>Video</b></td></tr>";
var url = "http://XXX.XXX.XX.XX:XX/PG_crud_experiment1/retrieve_all.php";
$.getJSON(url, function(json) {
$.each(json, function(i, v) {
alert(v.id);
myTable += "<tr><td>" + v.id + "</td><td>"
+ v.name + "</td><td>" + v.dob
+ "</td><td>" + v.address + "</td><td>"
+ v.image + "</td></tr>";
});
$("#emp_tb1").html(myTable);
});
};
The problem here is my button click is entering the Javascript function but I am getting an error saying it cannot access the URL where my PHP file is placed. The PHP is actually running a SELECT SQL and retrieving values from a database.
Below is a screenshot of my error on BB 10 simulator.
Can anyone please tell me why this problem is coming up? Are there any pre-requisites/procedures to be followed before the device can run some Javascript functions or to access the PHP scripts on server?XXX
回答1:
The solution is to edit the config.xml file of the project -
add the tag <access subdomains="true" uri="http://*URI name here*"/>
. Only then, Blackberry allows access permissions to a different domain.
回答2:
This could be a cross-site request issue - I'm suspecting that the PHP side doesn't accept requests from outside of its own domain.
How about putting this header at the top of your PHP file?
header('Access-Control-Allow-Origin: *');
回答3:
As anami said earlier you need to have cross domain origin enabled in your server php file. Also you need to have <access subdomains="true" uri="http://*URI name here*"/>
in config.xml for blackberry.
Having both of these in place should solve your issue.
来源:https://stackoverflow.com/questions/16605461/access-denied-to-php-from-blackberry-10-platform-using-phonegap-closed