2014-04-09 92 views
0
$(document).ready(function(){ 
/* The following code is executed once the DOM is loaded */ 

/* This flag will prevent multiple comment submits: */ 
var working = false; 

/* Listening for the submit event of the form: */ 
$('#addCommentForm').submit(function(e){ 

    e.preventDefault(); 
    if(working) return false; 

    working = true; 
    $('#submit').val('Working..'); 
    $('span.error').remove(); 
    console.log('Test javascript 1') 
    /* Sending the form fileds to submit.php: */ 

    $.post('comments/submit.php',$(this).serialize(),function(msg){ 
    console.log('Test javascript 2') 
     working = false; 
     $('#submit').val('Submit'); 

     if(msg.status){ 

      /* 
      / If the insert was successful, add the comment 
      / below the last one on the page with a slideDown effect 
      /*/ 

      $(msg.html).hide().insertBefore('#addCommentContainer').slideDown(); 
      $('#body').val(''); 
     } 
     else { 

      /* 
      / If there were errors, loop through the 
      / msg.errors object and display them on the page 
      /*/ 

      $.each(msg.errors,function(k,v){ 
       $('label[for='+k+']').append('<span class="error">'+v+'</span>'); 
      }); 
     } 
    },'json'); 

}); 

});当我在本地运行它然而,当我上传它,当我点击“提交”,并挂在它打破了服务器Javascript在本地运行,但在服务器上运行时发生中断

这个脚本工作正常“工作..” 这个问题似乎来自于线

$.post('comments/submit.php',$(this).serialize(),function(msg){ 

我无法弄清楚问题所在。谁能帮忙?

+0

您控制台中的任何错误?请将它们添加到您的问题。 – Stuart

+1

所有在*客户*上运行的,而不管它来自哪里。可能的问题是'comments/submit.php' - 你有没有在浏览器网络检查器中查看请求/响应以检查它的期望? –

+0

发现问题!你是对的,它在submit.php中 – user3516292

回答

0

您的comments/submit.php参数未指向服务器上的正确位置。将会对正在运行的URL进行某种修改,这与您的本地环境与生产服务器不同。

看看Chrome的“调试”菜单(或其他浏览器中的类似功能)中的“网络”选项卡,查看它试图去的位置。

最有可能的解决方案就像在您的帖子路径的前面添加/一样简单,但是您可能会丢失另一个或两个URL链。

相关问题