-1

few days ago I change my PHP version from 5.4 to 5.5 due to some code needed for render QR code. And today i found error in this function:

$(function changeStav() {

            $("#selPismoSet<?php echo $id;?>").change(function() {
                var del_id = $(this).attr("id");
                del_id = del_id.replace("selPismoSet","");
                var id = del_id;
                var val = $('#selPismoSet<?php echo $id;?> option:selected').val();

                $.ajax({
                    type: "GET",
                    url: "actions.php?action=changeStav",
                    data: 'id=' + id+ '&stav=' + val,
                    success: function(data){
                        e.preventDefault();
                        $('#content, #ok<?php echo $id;?>').html(data);
                        console.log();
                    }
                });

                return false;           
            });

        });

I got this error: enter image description here

I dont know where is the problem. Its possible that error is due to change PHP version?

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
Stanley01
  • 55
  • 8
  • 2
    So you have error "e is not defined" and still you couldn't figure out the problem? – dfsq Feb 23 '18 at 08:59
  • `e` is usually an JavaScript event object and has nothing to do with PHP, don't know what event do you want to prevent there? :) – xander Feb 23 '18 at 09:00
  • 1
    The php version has nothing to do with this – Rotimi Feb 23 '18 at 09:06
  • Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Rotimi Feb 23 '18 at 09:06
  • Isn't it a bit late running `preventDefault()` in the success method? – RiggsFolly Feb 23 '18 at 09:19

1 Answers1

0

You are missing an argument in your function. e is not defined

$(function changeStav() {

            $("#selPismoSet<?php echo $id;?>").change(function(e) {
                var del_id = $(this).attr("id");
                del_id = del_id.replace("selPismoSet","");
                var id = del_id;
                var val = $('#selPismoSet<?php echo $id;?> option:selected').val();

                $.ajax({
                    type: "GET",
                    url: "actions.php?action=changeStav",
                    data: 'id=' + id+ '&stav=' + val,
                    success: function(data){
                        e.preventDefault();
                        $('#content, #ok<?php echo $id;?>').html(data);
                        console.log();
                    }
                });

                return false;           
            });

        });
Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
jerome
  • 695
  • 6
  • 20
  • Isn't it a bit late running `preventDefault()` in the success method? – RiggsFolly Feb 23 '18 at 09:19
  • @RiggsFolly yes i think so too. actually i dont know the reason why did op added a `preventDefault()` in his function. – jerome Feb 23 '18 at 09:22
  • @jerome @RiggsFolly - i dont know why but without e.preventDefault() `$('#content, #ok').html(data);` cant load the div #content – Stanley01 Feb 23 '18 at 14:21