9

We are using extjs and webapi(C#) for our application. My form has a fileupload control. When we use form.sumbit() in extjs, it is not going to the success function.

WebApi code:

bool SaveData(Employee obj)
{
     return true;
}

Extjs code:

form.submit( {
               url: '../api/Empcontroller/SaveData',
               method: 'POST',
               headers: {
               'Content-Type': 'application/json'
                         },
               success: function ( fp, o )
               {


               },
               failure: function ( fp, o )
               {

               }
            } );

I'm getting the response as true in all browsers. In Chrome its coming into success, But in Firefox its not.

RajeshKdev
  • 6,365
  • 6
  • 58
  • 80

7 Answers7

2

Try adding in the dataType param like so:

form.submit({
   url: '../api/Empcontroller/SaveData',
   method: 'POST',
   headers: {
       'Content-Type': 'application/json'
   },
   dataType: 'json',
   success: function (fp, o) {

   },
   failure: function (fp, o) {

   }
});

I have also seen it done this way: (replace json_data_here with any data you need to send)

form.submit(Ext.Ajax.request({    
    url: '/../api/Empcontroller/SaveData',
    method: 'GET',
    jsonData: json_data_here,
    headers: {'Content-Type' : 'application/json' , 'Accept' : 'application/json'}
}));
cointilt
  • 698
  • 2
  • 8
  • 18
1

Seems like there's a FireFox bug that jacks the content-type...

JQuery - $.ajax ContentType Problem in Firefox

Community
  • 1
  • 1
Jasmine
  • 4,003
  • 2
  • 29
  • 39
1

try adding anonymous function inside submit instead of a json:

form.submit( function(){
               url: '../api/Empcontroller/SaveData',
               method: 'POST',
               headers: {
               'Content-Type': 'application/json'
                         },
               success: function ( fp, o )
               {


               },
               failure: function ( fp, o )
               {

               }
            } );
Pranav Singh
  • 17,079
  • 30
  • 77
  • 104
1

Try this out:

form.submit( function(){
    url: '../api/Empcontroller/SaveData',method: 'POST',
    headers: {'Content-Type': 'application/json'},
    success: function (fp, o ){},
    failure: function (fp, o ){}
});
A.L
  • 10,259
  • 10
  • 67
  • 98
1

hhhmmm. strange. I think i found the bug. FireFox doesn't like it when I set the 'asyncron' state on 'false' to tell the script to wait for the reply of the serverrequest.

so instead of http.open("GET", destURL, true); I am using http.open("GET", destURL, false);

Firefox dont accept asynchron Option on "false"

frompedro
  • 11
  • 2
1

I am not sure if this is the problem. But doesn't file upload require an enctype Try using

enctype = multipart/form-data

This might help

Infant Dev
  • 1,659
  • 8
  • 24
  • 48
0

Use the below code.

form.submit( {
               url: '../api/Empcontroller/SaveData',
               method: 'POST',
               headers: {
               'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
                         },
               success: function ( fp, o )
               {


               },
               failure: function ( fp, o )
               {

               }
            } );

I just changed the content type.

KiranPalode
  • 498
  • 3
  • 8
  • 23