1

Below are the script that I use on my website to send instant messages. It works fine in 99,9% of cases, but from time to time some user reports that he/she can't send messages. Today I received a new report from MIE 8.0 user. I checked server's logfiles and discovered that this script is being ignored by MIE 8.0. When user clicks "Send" button, instead of POST request, browser sends GET request with all form data to the same file where the form is located. This user says that a few days ago everything was working fine. I didn't change anything in my files and I don't think that this user a few days ago upgraded MIE to 8.0 (the most recent version is 9.0). I have this problem more than 3 years. There are not so many users who have reported this problem but anyway I want to find a solution. Is it possible that the script doesn't work because is located inside of instead of ?

Any ideas what may cause this problem? Thanks.

<script type="text/javascript">                                         
$(document).ready(function(){
$("#sendmessage").submit(function(){
    $("#note1").show().html('<div style="text-align: center;">Sending</div>');
    var str = $(this).serialize();
    $.ajax({
        type: "POST",
        url: "/messages.php?do=send",
        data: str,
        success: function(data) {
            if (data == "ERR1") {
                result = '<div class="red">Error1 1</div>';
                $(this).html(result);
            } 
            else if (data == "ERR2") {
                result = '<div class="red">Error2</div>';
            } 
            else {                              
                $("#fields").hide();
                result = data;
            }
            $('#note1').hide();
            $("#note").hide();
            $("#note").fadeIn(1000).html(result);
        }
    });
    return false;
  });
});
</script>

<form id="sendmessage" name="sendmessage" onsubmit="doCheck();">
...
<textarea></textarea>
...
<input type="submit" value="Send" onclick="doCheck();" />
</form>
user1821484
  • 273
  • 1
  • 4
  • 12
  • I am really not sure and could not find an example in the internet but I know IE uses a different object for AJAX request and maybe it assumes when there is a '?' in the url it is a GET method. Can you please try change the URL? you can use a hidden field for "do" data in the same form. – Onur Topal Nov 22 '12 at 11:15
  • they has javascript not enabled? :D – itsme Nov 22 '12 at 11:16
  • If @Onur is right, and the problem lies with the url, it might be worth trying submitting your data with the `data` option like so: `url: '/messages.php', data: { do : 'send', strdata : str }` and then access your str using `$_POST['strdata']` – rosshamish Nov 22 '12 at 14:29

1 Answers1

0

Look at this post to see if the solution helps you. That user was saying that the format of his URL was causing a GET instead of a POST as you suspected. Try this URL instead:

url: "/messages/?do=send"

OR

url: "/messages.php?do=send"

Or whatever the proper extension would be depending on your backend language.

Community
  • 1
  • 1
davidethell
  • 11,708
  • 6
  • 43
  • 63
  • I accept this answer, however I did something different. I added "do=send" to the form as a hidden element and leaved url: "/messages/". I asked the user if she can send messages now, but she didn't answer anything. But I see that she is sending messages, however I am not sure if she have not changed the browser. – user1821484 Nov 25 '12 at 10:26