php ajax jquery 发布示例错误 503
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19806821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ajax jquery post example error 503
提问by user2511140
When i click run button show this error in chrome console and don't alert anything
当我单击运行按钮时,在 chrome 控制台中显示此错误并且不发出任何警报
POST http://mysite/gd/add.php 503 (Service Unavailable)
index.php
索引.php
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body >
<script>
function go(){
$.ajax({ url: 'add.php',
data: {'q': ''},
type: 'post',
success: function(output) {
alert(output);}
});
}
</script>
<button onclick="go();">Run</button>
</body>
</html>
add.php
添加.php
<?php echo "Hello"; ?>
采纳答案by Krish R
I have tried your code in local environment, it is working fine. The reason for 503 error because of the Web server (running the Web site) is currently unable to handle the HTTP request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. Some servers in this state may also simply refuse the socket connection, in which case a different error may be generated because the socket creation timed out.
user2511140 : I add this code to show errors.my server is to busy and show error.i changed server and problem solved
我已经在本地环境中尝试过你的代码,它工作正常。503错误的原因是由于Web服务器(运行网站)当前由于服务器临时过载或维护而无法处理HTTP请求。这意味着这是一个暂时的情况,将在一些延迟后得到缓解。一些处于这种状态的服务器也可能简单地拒绝套接字连接,在这种情况下,由于套接字创建超时,可能会产生不同的错误。
user2511140 :我添加此代码以显示错误。我的服务器正忙并显示错误。我更改了服务器并解决了问题
$.ajax({ url: 'add.php',
type: 'post',
data: {'q': ''},
success: function(output) {
alert(output);},
error: function (request, status, error) {
alert(request.responseText);},
});
}
回答by Bj?rn Zschernack
so i know it is old, but i just solved this problem while working on a wordpress project. I got the same error message, because there was a difference between the Url of the admin-ajax - script, written in the header(www.url.de/admin-ajax.ph) - and the url to load the data from (www.urx.de/ajax.php)
所以我知道它很旧,但我只是在处理 wordpress 项目时解决了这个问题。我收到了相同的错误消息,因为 admin-ajax 的 URL 之间存在差异 - 脚本,写在标题(www.url.de/admin-ajax.ph)中 - 和从中加载数据的 url ( www.urx.de/ajax.php)
回答by Mifas
I think you should call with http://mysite/gd/add.php
or gd/add.php
URL
我认为你应该用http://mysite/gd/add.php
或gd/add.php
URL调用
$.ajax({ url: 'http://mysite/gd/add.php',
data: {'q': ''},
type: 'post',
success: function(output) {
alert(output);}
});
If above code is not working. Please check your .htaccess
file.
如果上面的代码不起作用。请检查您的.htaccess
文件。
回答by Parixit
Your current page is a.php
and you send ajax request to add.php
, so check whether they both are in same directory or not?
您当前的页面是a.php
并且您将ajax请求发送到add.php
,因此请检查它们是否在同一目录中?
If so then try following or else try absolute HTTP path.
如果是这样,请尝试遵循或尝试绝对 HTTP 路径。
$.ajax({ url: './add.php',
data: {'q': ''},
type: 'POST',
success: function(output) {
alert(output);
}
});