Reputation: 1
<!doctype html>
<html>
<head>
<title>My Site</title>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
</head>
<body>
Hello World
</body>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("http://35.9.22.104/Token",
{
Password: "Super_Secure",
Username: "Test_User",
grant_type: "password"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
<body>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>
Above is my HTML information.I'm trying to implement login functionality by using jQuery,aJAx. What I want to do is to send the data(username,password) to the server(http://35.9.22.104/Token) and the server are expected to return a long string token.
But I got an error "POST http://35.9.22.104/Token net::ERR_CONNECTION_TIMED_OUT". This is the screen shot image,headers The file "temp3.html" on the image is about my html code above.
Can anyone give me some suggestions? A lot of thanks!
Upvotes: 0
Views: 1425
Reputation: 214
the url that you are using has no "No 'Access-Control-Allow-Origin' header"
so add it in your PHP file
header("Access-Control-Allow-Origin: *");
$(document).ready(function(){
$("button").click(function(){
$.post("http://localhost/api/index.php,
{
Password: "Super_Secure",
Username: "Test_User",
grant_type: "password"
},
function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
i have used my local api it works fine
Upvotes: 1