javascript - jquery POST 响应成功但数据为空

标签 javascript jquery html post response

我使用 jquery 将帖子发送到我的 api 的 session 端点以获取登录 token 。请求返回成功,但数据为空。如果我在 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>

最佳答案

哇!我发现了问题,就是这么简单。我只需要在我的网址前面使用 http://。 感谢大家的时间和帮助!。

关于javascript - jquery POST 响应成功但数据为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35116069/

相关文章:

jquery - 如何在jsp中不选择的情况下获取jqgrid第一行数据?

html - 我不希望导航栏超过超大屏幕

javascript - 如何停止 iMacros JavaScript 脚本?

javascript - 获取两个日期格式的天数差异 (YYYY/MM/DD hh :mm)?

javascript - 在 JQuery 中生成另一个 HTML 表以输入更多小时数进行计算

html - 自动开始延迟加载图像,无需等待用户向下滚动页面

javascript - 每张图像上都有特定文本的幻灯片

javascript - Nuxtjs handler.call 不是函数

javascript - 使用 jquery 切换带有回调代码的图像

jQuery AJAX : dataType vs mimeType