2017-07-13 6 views
0

私は簡単なPOST XMLHttpRequestを作成しています。データをポストするだけでなく、ペイロードがURLに追加されています。 URLに付加されるデータのdoesntはとにかくありURIにペイロードを追加するXMLHttpRequest

var payLoad= JSON.stringify(ItemJSON);                  
var xmlhttp = new XMLHttpRequest();                 
xmlhttp.addEventListener("readystatechange", function() {           
    if (xmlhttp.readyState < 4){                  
    }                        
    else if (xmlhttp.readyState === 4) {                
     if (xmlhttp.status == 200 && xmlhttp.status < 300){           
      console.log("Success",xmlhttp.responseText);            
     }                       
    }else{                       
     alert("Error!! \\n There was an error while saving. Please retry again later.");   
       }                       
     });                         
     xmlhttp.open("POST", URL, false);                 
     xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");      
     xmlhttp.send(payLoad); 
} 

応答: https://sample.com/api/apipipelines?apiName=asdasdaaaaaa&orgUnit=ASA&apiProductName=asdasd&leadDeveloperName=Sandeep&leadDeveloperEmail=sa11as1%40sandsssy.com&baseUrl=%2Fapplication%2Foip%2Fv1%2Fcase-management%2F&projectOwnerName=alisa&projectOwnerEmail=sa%40sasssssndy.com

答えて

0

ことであるので、コンテンツ投稿しているときに使用されるヘッダー:

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); 

変更を

xmlhttp.setRequestHeader("Content-Type", "application/json"); 

参考:What is the difference between form-data, x-www-form-urlencoded and raw in the Postman Chrome application?

+1

ありがとうございました。ここでのもう一つのポイントは、私がフォームデータを投稿していたことです。しかし、私がフォームを削除したとき、それはうまくいった。 –