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

后端 未结 3 485
走了就别回头了
走了就别回头了 2021-02-05 23:14

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\',                   


        
相关标签:
3条回答
  • 2021-02-05 23:25

    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.

    0 讨论(0)
  • 2021-02-05 23:43

    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);
        }
    });
    
    0 讨论(0)
  • 2021-02-05 23:47

    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');}
    });
    
    0 讨论(0)
提交回复
热议问题