Jquery Ajax - 没有成功获得错误

时间:2015-07-10 00:55:35

标签: jquery ajax codeigniter codeigniter-3

有人可能弄清楚为什么每个ajax调用都会导致错误。这是我的问题。 enter image description here

代码是

   <select id="officer-id" placeholder="Choose an officer">
               <option value=ab1>ab1</option><option value=ab2>ab2</option><option value=rep1>rep1</option>
            </select>

html代码中的Id officer_id是

url:"<?=base_url()?>" + "Home/ajax_view"

public function ajax_view(){ return ; } 内容

$(document).ready(function() {

    var casters = ["marcusraven86","whit3rabbit87","jimmyjojo7"];
    var castersLive = [];

    for(i=0; (i < casters.length) && (i < 3); i++){

        var userName = casters[i];

        $.getJSON('https://api.twitch.tv/kraken/streams/' + casters[i] + '.json?callback=?', function(data) {

            console.log(data);

            if (data.stream === null){
                $('<div class="blogpost"></div>').append(
                '<p>' + userName + ': Offline</p>').appendTo('#blogblock');
            }
            else {  
            castersLive.push(casters[i]);
            $('<div class="blogpost"></div>').append(
                '<p>' + userName + ': Online</p>').appendTo('#blogblock');
            }   
        });
    }

    console.log(castersLive);

});

为什么我的代码不会在控制台中出现错误

时执行成功

1 个答案:

答案 0 :(得分:0)

试试这个:

$('#officer-id').change(function(){
    var officer_id;
    if(officer_id = $(this).val()){ //
        $.ajax({
          type:'POST',
          url:"http://62.231.118.52:9080/teste/random_test/form_validate.php",
          dataType: 'json',
          data:{'officer_id':officer_id},
          success:function(data){
                       alert(this.data ); 
           },
          error:function(data){
                    alert("error");
          }


        });
    }
});