Spring 3 jQuery Ajax删除 [英] Spring 3 jquery ajax delete

查看:96
本文介绍了Spring 3 jQuery Ajax删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试用jquery进行ajax删除,但出现HTTP错误400. 我正在搜索,发现jquery中的delete方法存在一些问题.

I am trying to do ajax delete with jquery but getting http error 400. I was searching and I've seen that there is some problems with delete method in jquery.

这是我的js,控制器(春季3)和来自Chrome的请求.

Here's my js, controller(spring 3) and request from Chrome.

如果您现在出了什么问题,请告知或提供一些链接.

If you now what is the mistake please tell, or give some links.

$.ajax({  
                url: 'additions/cancelUpload',  
                type: 'DELETE',  
                data: {filename : ui.draggable.get(0).file.name},  
                success: function (res) {  
                    alert(res);
                }  
            }); 

执行未通过此处:

@RequestMapping(value = "cancelUpload", produces="text/html")
    @ResponseBody
    public String cancelUpload(@RequestParam("filename")String filename, HttpSession session ){ 
... 
} 

请求:


Request URL:http://localhost:8080/WebStore/additions/cancelUpload
Request Method:DELETE
Status Code:400 Bad Request
Request Headersview source
Accept:*/*
Accept-Charset:windows-1251,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:uk-UA,uk;q=0.8,ru;q=0.6,en-US;q=0.4,en;q=0.2
Connection:keep-alive
Content-Length:17
Content-Type:application/x-www-form-urlencoded
Cookie:JSESSIONID=A7DF5CB262C460961BC7B5C7DCB23052
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/WebStore/items?form
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1
1X-Requested-With:XMLHttpRequest

Form Dataview URL encoded
filename:6648.jpg

响应标题


Connection:close
Content-Length:1043
Content-Type:text/html;charset=utf-8
Date:Sat, 26 May 2012 10:03:58 GMT
Server:Apache-Coyote/1.1
X-TraceId:4fc0a8f8-46
X-TraceUrl:/insight/services/traces/4fc0a8f8-46?type=json

推荐答案

我设法将请求接收为DELETE

I manage to recive request as DELETE

 @RequestMapping(value = "cancelUpload", produces="text/html" method = RequestMethod.DELETE)

但是用

$.ajax({  
            url: 'additions/cancelUpload',  
            type: 'POST',  
            data: {filename : ui.draggable.get(0).file.name, _method: 'DELETE'},  
            success: function (res) {  
                alert(res);
            }  
        }); 

您可以在 http://blog.springsource.org/2009/03/08/rest-in-spring-3-mvc/

如果某些主体现在如何发送真正删除的AJAX请求.请告诉我

IF SOME BODY NOW HOW TO SEND REALLY DELETE AJAX REQUEST. PLEASE TELL ME

这篇关于Spring 3 jQuery Ajax删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆