BloodRayne Blood
BloodRayne Blood

Reputation: 63

Jquery/Ajax Variable not defined

When i'm tryng to click the button i'm ghetting an error : popup is not defined , i have no ideea what to do

<input href="#dialog" type='button' value='Open' onclick="popup(<?php echo $image['image_id']; ?>); return false;" />

<script type="text/javascript">
    function popup(image_id){
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: 'popup.php',
                    data: 'image_id=' + encodeURIComponent(image_id),
                    success: function(data) { 
                        }
                });
            }
</script>

Upvotes: 0

Views: 1314

Answers (1)

ShankarSangoli
ShankarSangoli

Reputation: 69905

Are you using href attribute of this input element? If not then you don't need that. Also I would suggest you to attach the click handler using jQuery. But if your markup and server side code does not help then you can try this.

<script type="text/javascript">
            function popup(image_id){
                $.ajax({
                    cache: false,
                    type: 'POST',
                    url: 'popup.php',
                    data: 'image_id=' + encodeURIComponent(image_id),
                    success: function(data) { 
                        }
                });
                return false;
            }
</script>

<input href="#dialog" type='button' value='Open' onclick="return popup('<?php echo $image['image_id']; ?>');" />

Upvotes: 1

Related Questions