I am trying to code a simple customer mobile page. On the first page, i have names of each customer. onclick
of one of them, it's open this file contain code below, however no data is loading. But if I try the refresh page, it works!
<script type='text/javascript' language='javascript'>
window.onload=function()
{
url = 'http://whateverorigin.org/get?url=' +
encodeURIComponent('http://www.mydomain.com/myphpfile.php') + '&callback=?';
$.ajax({
url: url,
dataType: 'json',
timeout: 4000,
success: function(reponse){
a=reponse.contents.split(';');
document.getElementById("client").innerHTML = a[0] ;
document.getElementById("adresse1").innerHTML = a[1] ;
},
});
}
</script>
First off you dont need to include the '&callback=?';
param as jQuery will handle that automatically as long as you have dataType: 'JSONP'
$(document).ready(function(){
var encoded = encodeURIComponent('http://www.mydomain.com/myphpfile.php');
$.ajax({
url: 'http://whateverorigin.org/get?url='+encoded,
dataType: 'jsonp',
timeout: 4000
}).done(function(reponse){
//do your work
})
})