简体   繁体   English

使用jsonP和Codeigniter的跨域Ajax

[英]Cross domain ajax with jsonP and codeigniter

i have been battling with cross domain referencing for days now , i have implemented some examples targeted at public API's that i came across on stack overflow : Basic example of using .ajax() with JSONP? 我已经与跨域引用进行了几天的斗争,我已经实现了一些针对公共API的示例,这些示例是我在堆栈溢出时遇到的: 将.ajax()与JSONP一起使用的基本示例? and try to mix it up to work for me but to no avail , my code works on my local host but not on a remote server and here it is 并尝试混合起来为我工作,但无济于事,我的代码在我的本地主机上工作,但不在远程服务器上,这是

javascript : javascript:

function load_data()
{ var data_output = $('#data_output');

$.getJSON("http://localhost/my_CI_root/index/load_data/News/?callback=?", function(response) {
   $.each(response, function(i, item){
     var landmark = ' <p class="column-responsive half-bottom">'
            + '<img src="http://www.bytepixels.com.ng/decoy/main/report/'+ item.media  +'" alt="img">'
            + '<strong>' + item.subject + '</strong>'
            + '<em>'+ item.message + '</em>'
            + '</p><div class="decoration"></div>';

            console.log(response);
            data_output.append(landmark);
   });
});



 }

and my codeigniter function: 和我的codeigniter函数:

  function load_data($value)
  {
  header('Content-type: application/json');

  $results = $this->my_model->load_data($value); 

  echo $_GET['callback'] . '(' . json_encode($results) . ')';
  }

like i said it works on localhost , im aware of the cross domain constraint and from what i read , $.getJson() is suppose to solve this issue but when i point my URL to http://www.xxxx.com/index/load_data/News/?callback= ? 就像我说的那样,它可以在localhost上运行,即时通讯了解跨域约束,并且从我阅读的内容中得知,$。getJson()应该可以解决此问题,但是当我将URL指向http://www.xxxx.com/index时/ load_data / News /?callback = it gives me an error 404 , ive tried enabling query strings on Codeigniter but it didnt help , any help would be aprreciated . 它给我一个错误404,我尝试在Codeigniter上启用查询字符串,但是它没有帮助,将不胜感激。 thank you 谢谢

In the URL the filename should be index.php instead of index. 在URL中,文件名应为index.php而不是index。

404 error means you have got the wrong URL. 404错误表示您输入了错误的URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM