简体   繁体   中英

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? 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 :

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:

  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= ? it gives me an error 404 , ive tried enabling query strings on Codeigniter but it didnt help , any help would be aprreciated . thank you

In the URL the filename should be index.php instead of index.

404 error means you have got the wrong URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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