[英]Javascript works locally but breaks when running on server
$(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');
});
}); });
This script works fine when I am running it locally however, when I uploaded it to the server it breaks when I click 'submit' and hangs on 'Working..' The problem seems to come from the line 当我在本地运行该脚本时,该脚本运行良好,但是,当我将其上传到服务器时,单击“提交”并挂起“正在运行”时,该脚本会中断。问题似乎出在这行
$.post('comments/submit.php',$(this).serialize(),function(msg){
I cant work out what the problem is. 我无法解决问题所在。 Can anyone help?
有人可以帮忙吗?
Your comments/submit.php
parameter is not pointing to the correct location on your server. 您的
comments/submit.php
参数未指向服务器上的正确位置。 There is going to be some sort of ammending being done to the URL it is running from that is different in your local environment versus the production server. 将对其运行的URL进行某种修改,这与您的本地环境和生产服务器的环境不同。
Take a look at your Network tab in Chrome's Debug menu (or similar in another browser) to see where it's trying to go. 在Chrome的“调试”菜单(或其他浏览器中的类似功能)中查看“网络”标签,以查看尝试去的地方。
Most likely, the solution will be as easy as adding a /
to the front of your post path, but there might be another step or two in the URL chain that you're missing. 解决方法很可能就像在帖子路径的前面添加一个
/
一样简单,但是URL链中可能还缺少另外一两个步骤。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.