1
<script type="text/javascript" src="/scripts/jquery-1.6.2.min.js"></script> 
<script type="text/javascript" src="/scripts/jquery.form.js"></script> 

<script type="text/javascript"> 
$(document).ready(function(){
$("#SendReply").click(function(){                                      
    $(".error").hide();
    var hasError = false;
    var pathname = window.location.pathname;
    var random = Math.random();

    var messageVal = $("#InquiryResponse").val();
    if(messageVal == 'Type your response in this space ...') {
        $("#InquiryResponse").after('<span class="error"><br><br><font color="red">You forgot to type your response to the inquiry. Please type it in the above space and submit again.</font><br></span>');
        hasError = true;
    }


    if(hasError == false) {
        $(this).hide();
        if (jQuery.browser.msie != true) {
        $.post( "",
            { Detail: messageVal},
                function(data) {
                    //alert("For non IE");
                    $("#InqRespForm").slideUp("slow", function() {                 
                         $("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');                             

                });
        });
        }
        if (jQuery.browser.msie == true) {
            jQuery.ajaxSetup({async:false});

            $.post( pathname , { Detail: messageVal},function(data)
                {

                    $("#InqRespForm").width($("#InqRespForm").parent().width()).slideUp("slow");
                    $("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');                  
                });
            jQuery.ajaxSetup({async:true});         
        }   


    }

    return false;
});                        
});
</script> 





<form action="" method="post" id="InqRespForm" name=InqRespForm>
Reply to the above Inquiry : <br/>
<textarea rows="7" name="Detail" id="InquiryResponse" cols="60" colspan=2>Type your     response in this space ...</textarea>
<br/>

<input id="SendReply" name="Send" type="submit" value="Send Response" alt="Reply to  Inquiry" /> 

</form>

On form submit, I send an email out. Which works on FF, Chrome etc. But I've gone bald trying to make this work in IE8. I will buy you beer if you can point me to a solution.

Frustrated
  • 21
  • 1
  • 3
  • Why are you having IE doing a synchronous post and not the other browsers? – Manfre Jul 27 '11 at 13:36
  • No reason - what i posted evolved over a two day period when I tried it all. Nothing will make it work. Mind you - there is nothing wrong with the front end behavior. The form does slide up and show that the message has been sent - only no message gets sent in IE8. I think the problem is with $.post on IE. I could be wrong. I started using jQuery couple of days back. – Frustrated Jul 28 '11 at 05:11
  • possible duplicate of [Jquery post not working in IE 8 or earlier](http://stackoverflow.com/q/13997857/1699210) – bummi Aug 26 '13 at 10:42

4 Answers4

1

I figured it out. Im going to post the solution here in case it helps someone in future. The problem was with the url i was posting to. My url was a parameterised url and I was using a wrong syntax/format all along. The IE and non IE separation is not really needed. The answer lies in extracting the various components of the current url and pass it in $.post via the "data" array. Thanks for your inputs. Working code below:

<script type="text/javascript" src="/scripts/jquery-1.6.2.min.js"></script> 
<script type="text/javascript" src="/scripts/jquery.form.js"></script> 
<script type="text/javascript" src="/scripts/jquery.url.js"></script>
<script type="text/javascript"> 
$(document).ready(function(){
$("#SendReply").click(function(){                                      

    $(".error").hide();
    var hasError = false;
    var pathname = window.location.pathname;
    var random = Math.random();
    var kar_ = $.url.param("kar"); 
    var obj_ = $.url.param("obj");
    var me_ = $.url.param("me");


    var messageVal = $("#InquiryResponse").val();


if(messageVal == 'Type your response in this space ...') {
    $("#InquiryResponse").after('<span class="error"><br><br><font color="red">You forgot to type your response to the inquiry. Please type it in the above space and submit again.</font><br></span>');
    hasError = true;
}


if(hasError == false) {
    $(this).hide();

    $.post( "inqdetails.asp",
        { Detail: messageVal, kar: kar_, obj: obj_, me: me_},
            function(data) {

                $("#InqRespForm").slideUp("slow", function() {                 
                     $("#InqRespForm").before('<h1>Success</h1><p><font color="green">Your message has been sent.</font></p>');                             

            });
    });

}

return false;
});                        
});
</script> 
Frustrated
  • 21
  • 1
  • 3
0

Put this line within your HTML just after the <head> tag starts

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

It will work for IE8+

Sandeep Kumar
  • 1,193
  • 13
  • 14
0

$.post( "", ... ) might have caused the problem. I found that it works in most browsers except IE.

Rather use $.post(window.location, ... ) to post to the same page.

TimoSolo
  • 7,068
  • 5
  • 34
  • 50
0

Why are you doing this: jQuery.browser.msie ????

There is almost never a reason to detect the browser! And I can see absolutely nothing in your code that requires knowing what the browser is.

Ariel
  • 25,995
  • 5
  • 59
  • 69
  • 1
    I think they're doing it to eliminate the animation which could be slow on IE8 because of its notoriously slow JavaScript execution. – rkaregaran Jul 28 '11 at 02:58
  • 1
    I am doing things differently for msie because - the if you notice, I am trying to post the form into the same page and while the url="" works in all browsers, it does not work in IE. On the flip side, if I do specify the url explicitly using the pathname variable, it does not work in FF or Chrome. – Frustrated Jul 28 '11 at 05:13
  • If it helps, my url looks something like this -"[link]http://test.mysite.com/sho/me/tails.asp?krm=I&obj=3193&mid=709" Do you think the parameters in /tails.asp?krm=I&obj=3193&mid=709 is the problem? – Frustrated Jul 28 '11 at 05:49
  • 1
    Why not use document.location instead of pathname? I personally don't like to include the parameters in the url, putting them instead in the data parameter, but that said it should still work fine. – Ariel Jul 28 '11 at 06:35