Javascript 我如何在浏览器上运行ajax代码?它现在不工作了?
它在本地主机上工作,但在实时主机上不工作 请帮助输入此代码 我的html是这样的Javascript 我如何在浏览器上运行ajax代码?它现在不工作了?,javascript,php,json,ajax,codeigniter,Javascript,Php,Json,Ajax,Codeigniter,它在本地主机上工作,但在实时主机上不工作 请帮助输入此代码 我的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_comme
<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>
聊天
首先检查config文件夹中的config.php文件,确保第26行是$config['base_url']=''
我的建议是这样使用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>
$(文档).ready(函数(){
$(“#注释内容”).keypress(函数(event){
如果(e.which==13){
$(“#提交”).submit();
return false;//是否尝试观看控制台?是否可以指定“不工作”部分?另外,是否检查浏览器的开发人员工具中是否存在JavaScript错误?JavaScript代码中的错误不正确。应在此处弹出错误。您也可以使用相同的开发人员工具检查“网络”选项卡。AJAX请求,包括它的URL,应该在那里可见。感谢您的回复,它不起作用是按enter键并提交,我将尝试查找javascript errorsTry以查看您的基本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>