0

I am using jquery.iframe-transport.js to upload a file using IFrame & Ajax (using Internet Explorer) The file is correctly uploaded and the server responds back with appropriate response for every call. However, the response "data" in the callback function "complete" always contains the previous/older response. Even clearing cache and using a new browser doesn't seem to help. Any idea what must be happening?

$(function() {
    //alert("Loading");

    getLDAPUsers();
    //getDummyUsers();

    //This will submit the file content using Ajax via Iframe
    $("#myForm").submit(function() {
        alert("Submitting Ajax");
        $.ajax(this.action, {
            data: $(":text", this).serializeArray(),
            files: $(":file", this),
            //iframe: true,
            processData:false
        }).complete(function(data) {
        debugger;
            alert("Response from server ::: "+data.responseText);
        });
    });
b4hand
  • 9,550
  • 4
  • 44
  • 49
Aditi
  • 1
  • It looks like you're missing the trailing `()` on your [immediate function invocation](http://stackoverflow.com/questions/939386/immediate-function-invocation-syntax). – b4hand Nov 14 '14 at 01:46

1 Answers1

0

I would recommend you to use "success" and "error" instead, for example:

$(function() {
    $("#myForm").on('submit',function(event) {
    event.preventDefault();

    //alert("Loading");

    getLDAPUsers();
    //getDummyUsers();

    var request = $.ajax({
      type: 'POST',
      url: $(this).attr('action'),
      data: $(":text", this).serializeArray(),
      files: $(":file", this),
      //iframe: true,
      ifModified: true,
      cache: false,
      success: function (response, textStatus, xhr) {
        alert("Response from server ::: "+response);
      },
      error: function (xhr, textStatus, errorThrown) {
        alert('ERROR');
      }
    });
  });
})();
Kirbo
  • 381
  • 1
  • 12
  • ...and I noticed that your $('#myForm').submit(function(){}); didn't stop the normal form submit, which would be done like: $('#myForm').submit(function(e){ e.preventDefault(); $.ajax(this.action, { ... ... }); }); – Kirbo Nov 14 '14 at 02:01
  • Thank you guys, but both solutions don't seem to work. I am referring to this - http://cmlenz.github.io/jquery-iframe-transport/ – Aditi Nov 14 '14 at 03:52
  • I am now able to get the call back working. However, I see that there are 2 http requests sent when I do the Ajax post.. One is a GET which does not contain any file information, and the second is the POST, which is the actual request with file content. The callback "complete" is receiving the response form the GET call, which obviously not what I want. I am unable to figure why is the GET request being sent!! Any suggestions? Just to add, I am using IE9 – Aditi Nov 14 '14 at 22:17