繁体   English   中英

如何在现在无法运行的浏览器上运行 ajax 代码?

[英]How can I run ajax code on browsers it does not work now?

它适用于本地主机,但不适用于实时托管 请帮助使用此代码,我的 html 是这样的,

<div class="msg_box" style="left:5px">
  <div class="msg_head">chat

  </div>
  <div class="msg_wrap">
    <div class="msg_body" id="msg_body">
         <div  id="display_comment"></div>
         <div  id="msg"></div>
    </div>
     <form method="POST" id="comment_form">

     <input type="hidden" name="comment_name" id="comment_name" class="form-control" value="<?php echo $this->session->userdata('name') ?>" />


     <input type="hidden" name="idprod" id="idprod" class="form-control" value="<?php echo $prod_view->id; ?>" />
  <input type="hidden" name="comment_id" id="comment_id" value="0" />
  <div class="msg_footer"><textarea class="msg_input" name="comment_content" id="comment_content" rows="2"></textarea> <input type="submit" name="submit" id="submit" class="btn btn-info" value="Submit" /></div>
     </form>
</div>
</div>

jquery代码如下

    <link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script>
$(document).ready(function(){


$('#comment_content').keypress(function (eventt) {

  if (e.which == 13) {
    $('#submit').submit();
    return false;    //<---- Add this line
  }
});


 $('#comment_form').on('submit', function(event){
  event.preventDefault();
  var form_data = $(this).serialize();

  $.ajax({
   url:"<?php echo base_url(); ?>" + "index.php/home/add_comment/",
   method:"POST",
   data:form_data,
   dataType:"JSON",
   success:function(data)
   {
    if(data.error != '')
    {
     $('#comment_form')[0].reset();
     $('#comment_message').html(data.error);
     $('#comment_id').val('0');

     load_comment();

    }
    $('#msg_body').animate({scrollTop: 6000000}, 600);


   }
  })
 });



$(document).ready(function() {
    setInterval('load_comment', 5000);

});
 load_comment();




var RefreshTimerInterval = 1000;

function load_comment()
 {

  $.ajax({
   url:"<?php echo base_url(); ?>" + "index.php/home/fetch_comment/",
   method:"POST",
    data: {
      'idprod': $('#idprod').val()

                },
   success:function(data)
   {
    $('#display_comment').html(data);
  setTimeout(load_comment, RefreshTimerInterval);
   }

  })
 }
$(document).ready(function() {
    setInterval('load_comment', 500);
});
 $(document).on('click', '.reply', function(){
  var comment_id = $(this).attr("id");
  $('#comment_id').val(comment_id);
  $('#comment_name').focus();
 });

});



</script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    var RefreshTimerInterval = 1000; // every 5 seconds
    $(document).ready(getData);

    function getData() {
        $.get('<?php echo base_url(); ?>' + 'index.php/home/fetch_comment', function(data) {
             $('#display_comment').html(data);

             setTimeout(getData, RefreshTimerInterval);
        }
    }
</script>

它适用于本地主机,但不适用于实时托管 请帮助解决此代码是代码中的错误还是可能有文件 js 受此代码影响

首先检查 config 文件夹中的 config.php 文件并确保第 26 行是 $config['base_url'] = ' http://www.yourwebsite.com ';

我的建议是这样使用 base_url:

<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
   <script>
$(document).ready(function(){


$('#comment_content').keypress(function (eventt) {

  if (e.which == 13) {
    $('#submit').submit();
    return false;    //<---- Add this line
  }
});


 $('#comment_form').on('submit', function(event){
  event.preventDefault();
  var form_data = $(this).serialize();

  $.ajax({
   url:"<?php echo base_url('index.php/home/add_comment'); ?>",
   method:"POST",
   data:form_data,
   dataType:"JSON",
   success:function(data)
   {
    if(data.error != '')
    {
     $('#comment_form')[0].reset();
     $('#comment_message').html(data.error);
     $('#comment_id').val('0');

     load_comment();

    }
    $('#msg_body').animate({scrollTop: 6000000}, 600);


   }
  })
 });



$(document).ready(function() {
    setInterval('load_comment', 5000);

});
 load_comment();




var RefreshTimerInterval = 1000;

function load_comment()
 {

  $.ajax({
   url:"<?php echo base_url('index.php/home/fetch_comment'); ?>",
   method:"POST",
    data: {
      'idprod': $('#idprod').val()

                },
   success:function(data)
   {
    $('#display_comment').html(data);
  setTimeout(load_comment, RefreshTimerInterval);
   }

  })
 }
$(document).ready(function() {
    setInterval('load_comment', 500);
});
 $(document).on('click', '.reply', function(){
  var comment_id = $(this).attr("id");
  $('#comment_id').val(comment_id);
  $('#comment_name').focus();
 });

});



</script>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
    var RefreshTimerInterval = 1000; // every 5 seconds
    $(document).ready(getData);

    function getData() {
        $.get("<?php echo base_url('index.php/home/fetch_comment'); ?>", function(data) {
             $('#display_comment').html(data);

             setTimeout(getData, RefreshTimerInterval);
        }
    }
</script>

如果这没有帮助,你能在这里留下错误信息吗?

暂无
暂无

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

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