Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Ajax code not work in Internet Explorer

Hi E's, I have a part of my code does not work in Internet Explorer (tested with version 11), but work in major browsers like Firefox, chrome or safari.
This is the code:
    $.ajax({
    method:"POST",
    url:"processa.php",
    data:{"nj":numero_jogo, "fase":'3'},
    success:function(data, textStatus, jqXHR){},
    error:function(jqXHR, textStatus, errorThrown) { coneccao('1'); },
    });

Open in new window

I believe the reason for not work was this lines:
    success:function(data, textStatus, jqXHR){},
    error:function(jqXHR, textStatus, errorThrown) { coneccao('1'); },

Open in new window

Note:I got the code here in this question:https://www.experts-exchange.com/questions/28037240/jQuery-Treating-error-in-AJAX-call.html
What I have to do for this code work in i.e.?

The best regards, JC
Avatar of Gary
Gary
Flag of Ireland image

Code looks fine bar the extraneous comma at the end of the error line.
What's the error message?
Avatar of Pedro Chagas

ASKER

Hi Gary, I never inspect code in i.e., usually I use Firebug in FF.
What is the best software like firebug for i.e..
I have to see the error message!
Thank you.

~JC
Forget, it is F12.
You can use fiddler to check the data
Any trailing comma at the end?
Hi, I did some tests, and the problem is, that code in i.e. just work in the first request, if I repeat the request the php don't receive any information.
It's weird, because in the other major browsers the same project/code works.

~JC
Hi again, I use fiddler, and when I execute the first time the code the ajax made the request successful. When I try use again the code, fiddler don't show anything, no error, nothing.
In the attach image, you can see the information about the first request, maybe contain some important information:User generated image
-JC
Try accessing the url directly and see if you get an error, it's sometimes easier to debug than debugging an ajax call.
No php errors.

~JC
Can you put a test page online?
Hi, I will show you the project, maybe in that way one of you can help me:
This is the project: http://rdsrc.us/zufBE0
If you check the source code, between lines 1783 - 1840 you can see entire script and there are 48 blocks of the same code, each block each piece of puzzle.
The problem occurs when you start the game, and for each peace you move I do that Ajax call.
One important note, I created the JavaScript code from php, like this:
function codigo_jquery ($valor){
$code= '
        var movimento'.$valor.';
        $("#pecas'.$valor.'").click(function(){
        if(controlo == 0 && controlo != 2 && movimento'.$valor.' != 3){
        controlo = 1;
        var mede = $("#pecas'.$valor.'");
        actualleft = mede.position().left;
        var newleft = actualleft;
        if(EmEscuro == 0){
        newleft = newleft + 30;
        } else {
        newleft = newleft + 60;
        }
        newleft = newleft + "px";
        actualtop = mede.position().top;
        var newtop = actualtop;
        newtop = newtop + 10;
        newtop = newtop + "px";
        $("#selector_verde").css({"top": newtop, "left": newleft});
        $("#selector_verde").css("visibility", "visible");
        select = "#pecas'.$valor.'";
            } else if (controlo == 1 && select == "#pecas'.$valor.'" && controlo != 2 && movimento'.$valor.' != 3){
                $("#selector_verde").css("visibility", "hidden");
                controlo = 0;
                    } else if (controlo == 1 && controlo != 2 && movimento'.$valor.' != 3){
                        var nome_select;
                        movimento'.$valor.' = 3;
                        var nome_select = select.replace("#pecas", "");
                        window["movimento" + nome_select] = 3;    
                        $("#pecas'.$valor.'").css("z-index", zindex);
                        $(select).css("z-index", zindex);
                        zindex++;
                        var mede = $("#pecas'.$valor.'");
                        llleft = mede.position().left;
                        tttop = mede.position().top;
                        $("#selector_verde").css("visibility", "hidden");
                        $("#pecas'.$valor.'").animate({
                        left: actualleft, top: actualtop}, 500, function(){
                        movimento'.$valor.' = 0;
                        });
                        $(select).animate({
                        left: llleft, top: tttop}, 500, function(){
                        window["movimento" + nome_select] = 0;
                        });
                        controlo = 0;
                        n_jogadas++;
                        if(n_jogadas == 15){
                        numero_jogadas_interaccao();
                        }
                        console.log(n_jogadas);                                             
                        $.ajax({
                        method:"POST",
                        url:"ajax_prev.php",
                        data:{"nj":numero_jogo, "fase":\'3\'},
                        success:function(data, textStatus, jqXHR){},
                        error:function(jqXHR, textStatus, errorThrown) { coneccao(\'1\'); },
                        });                                                                                             
                        }
        });
';

echo $code;
}
$contador = 0;
foreach($array_sequencia as $valor){
    codigo_jquery($valor);
    $contador++;
}

Open in new window

I'm getting worried, because the game runs well on all major browsers, and ie is not going well.
Another thing that makes me confused is the fact that work well on the first Ajax call, but when I move the second piece of the game (puzzle) the code no longer works, but only in ie.
If you need more information, please tell me. I appreciate your good will, and it is very important to me resolve this problem, if I have problems with i.e., the project ends.

The best regards, JC
To facilitate matters to us all, I wrote an example that illustrates the real example, and that also does not work in ie:
I create the index.php file, that contains the jQuery code with Ajax. Also I create the file processa.php that send a email every time the file is sought.
Every time I click in the div botao, the alert "is working" appear. In tests never detected any error, always appear the alert "is working" (sucess).
The problem is, I just receive one, just one email, if I click thousands of times, no metter, I just receive a single email, not a thousands emails as it was supposed.
Index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="../../ficheiros_apoio/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="botao">here</div>
<script>
<? function codigo_jquery ($valor){
$code= '
    $("#botao").click(function(){
    var numero_jogo = 1;
    $.ajax({
    method:"POST",
    url:"processa.php",
    data:{"nj":numero_jogo, "fase":\'3\'},
    success:function(data, textStatus, jqXHR){ sucesso();},
    error:function(jqXHR, textStatus, errorThrown) { erro();},
    });
    });    
    ';

echo $code;
}
codigo_jquery("10");
    ?>
        function erro(){
        alert("not work");
            }
    
    function sucesso(){
        alert("is working");
    }
 </script>  
 </body>
 </html>

Open in new window

processa.php:
<?
mail("xxxxxxx@xxxxxxx.com", "chegou", "chegou");
?>

Open in new window

Invite to test yourselves.

The best regards, JC
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've requested that this question be deleted for the following reason:

HI E's, The problem was the version of jquery file, I change the file to the most recent Jquery file, and the problem was overcome. Sorry for any lost time.

The best regards, JC
Hello. I don't want delete the question, because while I was writing @Slick812 also is writing the solution, and therefore did not see his response.
It would be unfair to close the issue because @Slick812 gave me the solution.
Thank you for your attention.

The best regards, JC
The correct answer is:
<<<the IE ver 11 is NEW, so I would use the NEWEST version of jquery which is -
jquery/1.11.0>>>