11

I have to do a POST from my ExtJs script in order to delete something from my DB:

Ext.Ajax.request({
    url: 'deleteRole.html',
    method: 'POST',          
    headers: {'Content-Type': 'text/html'},
    waitTitle: 'Connecting',
    waitMsg: 'Sending data...',                                     
    params: {
        "rolename" : rolename
    },
    scope:this,
    success: received,                                    
    failure: function(){console.log('failure');}
});

when the post is sent i can see in the firebug the rolename in font but not as a param. I would like to show you another post (made with spring:form) relative to the user registration. If i inspect the post i can see the following:

image
(source: subirimagenes.com)

And i can get the parameters in my controller using @RequestParam.

But in the post that i have problems i can't see the parameters part, i can only see the Font(Fuente) part:

image2
(source: subirimagenes.com)

As a consequence, my spring controller does not detect any parameter. Is it something wrong in my POST?

Thank you

Community
  • 1
  • 1
mannuk
  • 1,259
  • 5
  • 21
  • 43

3 Answers3

11

The problem is that you are using the line headers: {'Content-Type': 'text/html'}, in your original question. This would set the content to text/html instead of the content being post data.

Reimius
  • 5,694
  • 5
  • 24
  • 42
8

I solved it with the following code:

var rolename = 'myRol';
Ext.Ajax.request({
    url: 'deleteRole.html',
    method: 'POST',          
    params: {
        rolename: rolename
    },
    success: received,                                    
    failure: function(){console.log('failure');}
});
mannuk
  • 1,259
  • 5
  • 21
  • 43
  • 1
    You should at least give credit to the answer that helped you solve the issue. – Eric Jun 19 '13 at 15:49
  • He solved it before I posted, I just thought he might want to know why his answered solved it. This is assuming he just tried things till it worked and not known why. – Reimius Jun 19 '13 at 21:35
7

I'm using this in a Sencha Touch app. I had to add an extra config called jsonData and make it true or else nothing is passed to my endpoint url.

Ext.Ajax.request({
    url: endpoint,
    method : "POST",
    headers: {
        'Content-Type': 'application/json'
    },
    params : {add: formattedAddress, lat: latitude},
    jsonData: true,
    useDefaultXhrHeader : false,
    withCredentials: true,                
    success : function(response) {
        Ext.Msg.alert("Success", 'yea');
    },
    failure : function(response) {
        var respObj = Ext.JSON.decode(response.responseText);
        Ext.Msg.alert("Error", respObj.status.statusMessage);
    }
});
paddys_1
  • 161
  • 2
  • 4