Solved

Ajax code not work in Internet Explorer

Posted on 2014-03-28
15
1,485 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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
 
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 34

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Asp in script 6 39
How  can  I extract  Id  from a  URL  using  Javascript? 12 30
html border input line 7 16
Validating textboxes in red square borders. 2 17
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

821 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