How do send DELETE Ajax Json?
How do send DELETE Ajax Json?
1ticket
Posts: 11Questions: 8Answers: 1
I have the following code:
remove: {
type: 'DELETE',
url: _config.apis.dti1ticketapps.credentialsUrl,
headers: { 'x-api-key': _config.apis.dti1ticketapps.devtoken},
contentType: 'application/json',
data: function (d) {
d = JSON.parse(JSON.stringify(d))
let { internal_id, ...payload} = d.data
ids = {ids:Object.keys(payload)}
return JSON.stringify(ids);
},
},
In chrome, the request looks like it's getting split up... How do I just send a JSON object?
{
"ids": [
"0f7da995eccb47509e7352a18c342142",
"460eed00a0aa4e0c8ba0c33ae67f0bd6",
"a99e45e88f1645bab2945fe181cb9240",
"b7180ec35b8f45759e14051ae6435142",
"b8109a29a16342a2a69d73b84f8f12af"
]
}
Here is what it's sending (copied request as cURL):
curl 'https://endpoint.com/v1?0=%7B&1=%22&2=i&3=d&4=s&5=%22&6=%3A&7=%5B&8=%22&9=0&10=f&11=7&12=d&13=a&14=9&15=9&16=5&17=e&18=c&19=c&20=b&21=4&22=7&23=5&24=0&25=9&26=e&27=7&28=3&29=5&30=2&31=a&32=1&33=8&34=c&35=3&36=4&37=2&38=1&39=4&40=2&41=%22&42=%2C&43=%22&44=4&45=6&46=0&47=e&48=e&49=d&50=0&51=0&52=a&53=0&54=a&55=a&56=4&57=e&58=0&59=c&60=8&61=b&62=a&63=0&64=c&65=3&66=3&67=a&68=e&69=6&70=7&71=f&72=0&73=b&74=d&75=6&76=%22&77=%2C&78=%22&79=a&80=9&81=9&82=e&83=4&84=5&85=e&86=8&87=8&88=f&89=1&90=6&91=4&92=5&93=b&94=a&95=b&96=2&97=9&98=4&99=5&100=f&101=e&102=1&103=8&104=1&105=c&106=b&107=9&108=2&109=4&110=0&111=%22&112=%2C&113=%22&114=b&115=7&116=1&117=8&118=0&119=e&120=c&121=3&122=5&123=b&124=8&125=f&126=4&127=5&128=7&129=5&130=9&131=e&132=1&133=4&134=0&135=5&136=1&137=a&138=e&139=6&140=4&141=3&142=5&143=1&144=4&145=2&146=%22&147=%2C&148=%22&149=b&150=8&151=1&152=0&153=9&154=a&155=2&156=9&157=a&158=1&159=6&160=3&161=4&162=2&163=a&164=2&165=a&166=6&167=9&168=d&169=7&170=3&171=b&172=8&173=4&174=f&175=8&176=f&177=1&178=2&179=a&180=f&181=%22&182=%5D&183=%7D' -X OPTIONS -H 'Access-Control-Request-Method: DELETE' -H 'Origin: http://localhost:8080' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36' -H 'DNT: 1' -H 'Access-Control-Request-Headers: content-type,x-api-key' --compressed
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
This is sending a JSON string which the server code will need to parse to place into a variable within the language of the server code. How to do that depends on the language you are using.
Are you needing a different format than what you show?
ids = {ids:Object.keys(payload)}
is creating the JS object you posted above. This will need to be changed if you want something different.What are you expecting to send?
Kevin
You may also need to use
ajax.deleteBody
. Some HTTP servers don't support a body in a DELETE request, which is why it is disabled by default.Allan