weixin_33699914 2016-12-10 20:48 采纳率: 0%
浏览 44

Ajax-Web API的令牌请求

I'm doing some code here i need to send a request from javascript client with a username and a password to a web api. In this request i need to receive a token.

This is what i have now:

  var loginData = {
     grant_type: 'password',
      //Username and password are fill by the user in the text fields
     username: username, 
     password: password
 };

  $.ajax({
    type: 'POST',
    crossDomain: true,   //I'm having some problems with: Access-Control-Allow-Origin
    crossOrigin:true,
    contentType: "application/json",
    url: 'https://localhost:44380/Token',
    data: loginData
}).done(function (data) {
    self.user(data.userName);
    sessionStorage.setItem("Token", data.access_token);
}).fail("Error");

When i execute the client i receive erros related to Access-Control-Allow-Origin

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

And Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Any ideas? I'm a rookie in web ...

I'm not sure if i'm doing the ajax request correctly...

  • 写回答

2条回答 默认 最新

  • weixin_33709219 2017-05-02 21:09
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法
  • ¥15 dnat基础问题,本机发出,别人返回的包,不能命中
  • ¥15 请各位帮我看看是哪里出了问题