简体   繁体   中英

How to make a PUT JQuery Ajax request to JsonBlob

I'm trying to call a PUT request on JsonBlob but i get this error

"XML interpretation error: no root element found Address: https://jsonblob.com/api/jsonBlob/43c83fba-f591-11e8-85a9-1542923be246 Row number 1, column 1:"

Here is the function:

backup : function(data){
    data = JSON.stringify(data);
    console.log(data);
    var url =  "https://jsonblob.com/api/jsonBlob/43c83fba-f591-11e8-85a9-1542923be246";
    $.ajax({
        url: url,
        type: "PUT",
        data: data,
        dataType: 'json',
        error:function(xhr, status, e){
            console.log(status)
        }
    });

The API's error message indicates that it is trying to parse your request as XML.

The documentation for the API shows a Content-Type header on the request:

 HTTP/1.1 200 OK Content-Type: application/json Transfer-Encoding: chunked {"people":["fred","mark","andrew"]} 

You haven't included that.

Add it:

$.ajax({
    url: url,
    contentType: "application/json"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM