weixin_33744854 2017-01-02 12:29 采纳率: 0%
浏览 47

AJAX Jquery,POST无法正常工作

for the GET method on URL https://futuregroupb.atlassian.net/rest/api/2/issue/LHEL-24 i get response from browser (cookie based), curl command as well as my ajax jquery code.

However when i hit the same URl for POST method i get an error "XMLHttpRequest cannot load the URL Response for preflight has invalid HTTP status code 403"

However I get a response on the curl command perfectly fine

curl -D- -u admin:Welcome@123 -X POST --data @"/root/input.json" -H "Content-Type: application/json" https://futuregroupb.atlassian.net/rest/api/2/issue/

Cross origin is also not a problem, i am using a CORS extension to sort that matter.

Below is my code:

$("#createbtn").click(function(){
    var val1 = $("#Summary").val();
    var val2 = $("#Des").val();
    var sendInfo = {
        fields: {
           project:{  id: '10000' },
           summary: val1,
           description: val2,
           issuetype: {
              id: '10101'
           }
       }
    };
    $.ajax({
        type: 'POST',
        contentType: 'application/json',
        dataType: 'json',
        data: sendInfo,
        url: 'https://futuregroupb.atlassian.net/rest/api/2/issue/',
        beforeSend: function (xhr){ 
        xhr.setRequestHeader('Authorization', make_base_auth("admin", "Welcome@123")); 
        },
        success: function (data) {
            console.log('success', data );
           alert(sta);
        },
        error: function (data, status, error) {
          console.log('error', data, status, error);
        }
    });
})
function make_base_auth(user, password) {
  var tok = user + ':' + password;
  var hash = btoa(tok);
  return "Basic " + hash;
 }

Please help.

Thanks Ramneek

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿