Solved

Ajax code not work in Internet Explorer

Posted on 2014-03-28
15
1,461 Views
Last Modified: 2014-03-29
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:http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_28037240.html
What I have to do for this code work in i.e.?

The best regards, JC
0
Comment
Question by:Pedro Chagas
15 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39963049
Code looks fine bar the extraneous comma at the end of the error line.
What's the error message?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963064
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963067
Forget, it is F12.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39963090
You can use fiddler to check the data
Any trailing comma at the end?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963117
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963132
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:the first request
-JC
0
 
LVL 58

Expert Comment

by:Gary
ID: 39963135
Try accessing the url directly and see if you get an error, it's sometimes easier to debug than debugging an ajax call.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963139
No php errors.

~JC
0
 
LVL 58

Expert Comment

by:Gary
ID: 39963146
Can you put a test page online?
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39963988
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39964140
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
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 500 total points
ID: 39964144
hello Pedro Chagas, ? ? It does seem odd that it works the first time and not after that?
I see some things I would change in the code.
In my browser if I place " around the object property names it kills my javascript

$.ajax({
    method:"POST",
    url:"processa.php",
    data:{nj:numero_jogo, fase:"3"}, // DO NOT place " on the property Name
    success:function(data){},// don't use param, don't call
    error:function(jqXHR, textStatus, errorThrown) { coneccao('1'); }
// remove the comma here
    });

the IE ver 11 is NEW, so I would use the NEWEST version of jquery which is -
jquery/1.11.0

It helps me greatly in jquery ajax to separate the parts of the ajax, instead of mashing them all together, I can understand and debug it better like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
//
//
var ajxOptions = {
    url: "ajax_prev.php",
    type: "POST",
    data: {nj:numero_jogo, fase:"3"},
    dataType: "text",
    timeout: 3500}

var aj = $.ajax(ajxOptions);

aj.done(function( received ) {// success
    $('#ajaxRe').html(received);
	});

aj.fail(function(xhr, error1, err) { //error
  coneccao("1"); });

Open in new window

But it is difficult to debug code if it works sometimes and then don't
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39964158
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39964159
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
0
 
LVL 3

Author Comment

by:Pedro Chagas
ID: 39964161
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>>>
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now