Dunque $.ajax non supporta il cross browsing, mentre sono riuscito a far funzionare la cosa su browser da pc, ma non da blackberry, con jsonp
Qualcuno sa a il motivo????
posto il codice dell'index:
codice:
<!DOCTYPE html>
<html>
<head>
<title>try phpinfo</title>
<meta id="viewport" name="viewport" content="user-scalable=no,width=device-width" />
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/include.js"></script>
</head>
<body>
<div id="container">
<div id="button">
<h2>Press the button</h2>
<button type="button" id="btnGPSDefault" onClick="callTheJsonp();">Print something</button>
</div>
<div id="areaTest"></div>
</div>
</body>
</html>
il file php
Codice PHP:
<?php
// get the callback function name
$callback = '';
if (isset($_GET['callback']))
{
$callback = filter_var($_GET['callback'], FILTER_SANITIZE_STRING);
}
// make an array with some random values.. so you would see that the results are fetched each time you call this script
$array = array(
'item_id' => rand(1,13),
'price' => rand(14,17),
'quantity' => rand(18,30)
);
// output this array json encoded.. the callback function being the padding (a function available in the web page)
echo $callback . '('.json_encode($array).');';
?>
e il js
codice:
function callTheJsonp()
{
var url = "http://www.dominiodiprova/script.php?callback=parseRequest";
var script = document.createElement('script');
script.setAttribute('src', url);
document.getElementsByTagName('head')[0].appendChild(script);
}
function parseRequest(response)
{
if(response)
document.getElementById('areaTest').innerHTML = 'Ok';
else
document.getElementById('areaTest').innerHTML = 'Failed to retreive data';
}