【发布时间】:2016-05-09 01:12:40
【问题描述】:
我使用 jquery 将帖子发送到我的 api 的会话端点以获取登录令牌。请求返回成功,但数据为空。如果我在 cURL 中执行相同的请求,它会返回 json。 我是 jquery 的新手。有人对可能出现的问题有什么建议吗?
<!DOCTYPE html>
<HTML>
<HEAD>
<TITLE> login </TITLE>
</HEAD>
<LINK rel="stylesheet" type="text/css" href="login.css" />
<BODY>
<DIV id="container">
<DIV id="header">
<IMG src="image.bmp" alt="logo" style="width:64px;height:64px;"/>
<H1> my service </H1>
</DIV>
<DIV id="content">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(document).ready(function()
{
$("button").click(function()
{
$.post("www.mydomain.com/api/session",
{
username: "batman",
password: "123"
},
function(data,status)
{
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
<DIV id="loginform">
<form method="POST">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<button> welcome! </button>
</form>
</DIV>
<DIV id="description">
<P>mydomain description</P>
<P>Join now to see what people are doing near you!</P>
</DIV>
<DIV id="register">
<P>Dont have an account with us? </P>
<P>Register here now !!</P>
</DIV>
</DIV>
<DIV id="nav">
</DIV>
</DIV>
</DIV>
</BODY>
</HTML>
【问题讨论】:
-
你检查了控制台是否有同源错误?
标签: javascript jquery html post response