Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs 4.2: How to send parameters properly in a Ext.Ajax.Request POST

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

like image 569
mannuk Avatar asked Jun 19 '13 07:06

mannuk


2 Answers

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);
    }
});
like image 155
paddys_1 Avatar answered Sep 24 '22 16:09

paddys_1


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.

like image 39
Reimius Avatar answered Sep 20 '22 16:09

Reimius