Question

When i click run button show this error in chrome console and don't alert anything

POST http://mysite/gd/add.php 503 (Service Unavailable) 

enter image description here

index.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 echo "Hello"; ?>
Was it helpful?

Solution

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

$.ajax({ url: 'add.php',
         type: 'post',
         data: {'q': ''},
         success: function(output) {
         alert(output);},
    error: function (request, status, error) {
        alert(request.responseText);},
});
}

OTHER TIPS

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)

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?

If so then try following or else try absolute HTTP path.


$.ajax({ url: './add.php',
         data: {'q': ''},
         type: 'POST',
         success: function(output) {
             alert(output);
         }
});

I think you should call with http://mysite/gd/add.php or 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top