calling delete rest api by jquery
I had called the GET REST API by following code :
$.getJSON('http://myapisite.com/user/1?callback=?', function(msg){
console.log(msg);
});
But for calling DELETE REST API through jquery what i had tried is :
$.ajax({
url: 'http://mysite.com/user/1?callback=?',
type: 'DELETE',
dataType: 'json',
data: '',
succ开发者_运维知识库ess: function(response) { console.log('PUT completed'+response); }
});.
and this api is not being called , I want to know how should i call the DELETE REST API .
Thanks
You are trying to do a cross-domain request. This means that you cannot use XMLHttpRequest
(the basis of AJAX) because of the same-origin policy. You are using a workaround called JSONP, which works by inserting <script>
tags into your document.
Script tags will always fetch content via GET, so you can't do a DELETE, POST, PUT or suchlike with them.
The best workaround would be to have a script on your own server that proxies the DELETE request for you.
精彩评论