3

My form sends perfectly well in Chrome and Firefox, with no errors displayed in firebug. However, in IE the form fails to send. I have narrowed it down to the $.post() function, which just doesnt seem to be called in IE. The callback function works, the call to the php file does not.

I have created a fiddle here - deleted to prevent spam - Enter your own email address in the supplied field. Submitting the form will send a confirmation email to you. This fiddle works in Chrome and Firefox, but not IE.

I have read questions with similar issues, but none solve mine.

In short, why does the $.post() function not work in IE?

The line in my .js:

var formData = $('#promo-form').serialize();
$.post('http://dynamic.lotterywest.wa.gov.au/promo-order/order.php', formData).always(formSent);
lukeocom
  • 3,243
  • 3
  • 18
  • 30

2 Answers2

2

If you are using the always utility, the callback will trigger irrespective of whether your ajax request was success or error. See the docs.

Form your post request target, your ajax call appears to be a cross domain call. So check in the chrome-inspctor or firbug console for more info. $.ajax has crossdomain settings which will get you going on Firefox and chrome but it will still fail on IE browsers where XMLHttpRequest objects are not supported.

So just because the callback you given on the always part is triggered, you cannot confirm that the ajax request was success.

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101
  • Yeah I'm aware of that. I have to use .always to solve a bug I was facing from the CMS/framework. – lukeocom May 29 '13 at 07:46
  • @lukeocom : How did you say it worked on firefox and chrome? are you sure the ajax request was success? – Mithun Satheesh May 29 '13 at 07:49
  • No you are probably right, which would explain why I need to use .always. The problem is the prod server doesnt have php, so I have to serve the php from a different one. I dont get any errors or warnings when submitting in FFox or Chrome... – lukeocom May 29 '13 at 08:02
  • 1
    my god!!.. **then why cant you host all these in the server where you hosted php**? – Mithun Satheesh May 29 '13 at 09:22
  • haha that would be silly. The plan is to re-write the script in Python. – lukeocom May 30 '13 at 00:25
  • The same origin policy of browsers is the issue. Ill need to find a way around this. But as this php file is the only use of php for the entire site, it is neither practical nor possible to migrate the entire site to an apache server. – lukeocom May 30 '13 at 01:47
  • if you could upvote my question that would be appreciated. Im not sure why it was down-voted in the first place. – lukeocom May 30 '13 at 01:48
-1

Try like this

$('#promo-form').live("submit",(function(){
            forma = $(this);
            serial = $(forma).serialize();
...../
});

It will work or the issue was with IE security restrictions and adding json to POST.

$.support.cors = true; //  cross-site scripting
        $.ajaxSetup({ cache: false });          

        var request = $.ajax({
            type: "POST",
            url: $("#YOUR FORM").attr("action"),
            data: $("#YOUR FORM").serialize(),
            sync: false,
            dataType: 'jsonp',
            crossDomain: true        
        });
Abraham K
  • 624
  • 1
  • 8
  • 24
  • `$.support.cors = true; // cross-site scripting` — This overrides jQuery's detection of CORS support in the browser. At best this will make things break more in browsers that don't support CORS. – Quentin Apr 21 '16 at 11:58
  • `sync: false,` — You misspelt `async` – Quentin Apr 21 '16 at 11:58
  • `dataType: 'jsonp',` — JSONP is incompatible with synchronous requests and with POST requests. – Quentin Apr 21 '16 at 11:59