weixin_33744854 2013-10-30 02:57 采纳率: 0%
浏览 26

Ajax数据未加载

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>
  • 写回答

1条回答 默认 最新

  • weixin_33705053 2013-10-30 03:03
    关注

    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 
        })
    })
    
    评论

报告相同问题?