简体   繁体   中英

Please help! - event.returnValue is deprecated. Please use the standard event.preventDefault() instead

I have this message when I using ajax with Google Chrome event.returnValue is deprecated. Please use the standard event.preventDefault() instead I installed new G.Chrome and new jquery library, but it's not giving effect. And my code works well in Mozilla Firefox. I have file with jquery code - edit.php and action file editting.php Code of edit.php:

 $('#submit').click(function(){  
      //if( this.value == "apl" )  
       var id = $("#inf_id").val();
       var text = $("#text").val();
       var title = $("#title").val();
      $("#imgLoad").show(); // Показываем прелоадер

      //setTimeout('$("#imgLoad").show()', 1000);
         $.ajax({  
                url: "editting.php",  
                type: "POST",
                data: {"inf_id": id,"title": title,"text":text},
                cache: false,  
               success: function(response){ 
               //////////////////////////// 
    alert(response);               
               //////////////////////////////
            if(response == 0){ // Смотрим ответ от сервера и выполняем соответствующее действие
                //alert("Больше нет записей");  
                $("#imgLoad").hide();
                $("#success_div").show();
                $("#alert_div").hide(); 
                $("#empty_infs_div").hide();                    
                setTimeout('$("#success_div").hide();', 2000);  

                $("#empty_text").hide();
                $("#empty_title").hide();                                   
            }else if(response == 1){
                $("#imgLoad").hide();
                $("#success_div").hide();
                $("#alert_div").show(); 
                $("#empty_infs_div").hide();
                setTimeout('$("#alert_div").hide();', 2000);    

                $("#empty_text").hide();
                $("#empty_title").hide();
            } /*else if(response == 2){
                $("#imgLoad").hide();
                $("#success_div").hide();
                $("#empty_infs_div").show();
                $("#alert_div").hide();                         
                setTimeout('$("#empty_infs_div").hide();', 2000);
            }*/

            else if(response == 2 || response == '2'){
                $("#empty_text").hide();
                $("#empty_title").show();

                $("#imgLoad").hide();
                $("#success_div").hide();
                $("#empty_infs_div").hide();
                $("#alert_div").hide(); 
                setTimeout('$("#empty_title").hide();', 2000);
                }
            else if(response == 3){ //if(response == 4)     
                $("#empty_text").show();
                $("#empty_title").hide();

                $("#imgLoad").hide();
                $("#success_div").hide();
                $("#empty_infs_div").hide();
                $("#alert_div").hide(); 
                setTimeout('$("#empty_text").hide();', 2000);
                }

            }//success  
            }); 

        });  

and editting.php:

                <?
            include("site_blocks/bd.php");
            if (isset($_REQUEST['inf_id'])) {$id = $_REQUEST['inf_id']; 
            if ($id == '') {unset($id);}}

            if (isset($_REQUEST['title'])){$title = $_REQUEST['title']; 
            if ($title == '') {unset($title);}}

            if (isset($_REQUEST['text']))  {$text = $_REQUEST['text']; 
            if ($text == '' || $text == '<br>' ) {unset($text);}}

            if (isset($title) && isset($text))
            {
                mysql_query('SET NAMES utf8');ob_clean();
                $update_infs = mysql_query ("UPDATE data SET title='$title',text='$text' WHERE id='$id'");      

                if($update_infs==1) {sleep(1); echo 0;}
                else {sleep(1); echo 1; }
            }

            else 
            {sleep(1);
            if (!isset($title)) {echo 2;}
            else if(!isset($text)) {echo 3;}
            }

            ?>

Alert is works, shows me results 0,1,2,3. But browser Chrome isn't reacting to this numbers. Mozilla reacts as well as I expected. Anyone can help me, please)? Thanks a lot))

event.returnValue is deprecated. Please use the standard event.preventDefault()

is just a warning (see here ), it should work in chrome and firefox! if its not working in chrome you should check your code: for example:

setTimeout('$("#success_div").hide();', 2000); 

should be changed to

setTimeout($("#success_div").hide(), 2000); 

the first parameter of setTimeout() should be a function (see here ), not a string

[edit] corrected the semicolon leftover

i checked your js-code with jslint and there are 2 main errors, the one above with setTimeout "Implied eval is evil. Pass a function instead of a string." and one error with your conditions

Expected '===' and instead saw '=='.
line 32 character 33:    } else if (response == 1) {

but this one shouldnt make the code not working

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM