Passing PHP variable to Jquery without refresh

前端 未结 2 1290
执笔经年
执笔经年 2021-01-27 21:44

I apologize upfront for my lack of jquery knowledge. In this website I am building, a user is presented with a number of thumbnail images representing plants. When a thumbnail i

2条回答
  •  萌比男神i
    2021-01-27 22:07

    Im pretty sure you dont need to query PHP each time ... something like this would work :

    
    

    This would be the output from your server side (php if thats what your using) - it stores the ID of the image in the data attribute

    JavaScript :

    $(document).ready(function() {
       $('.imglink').click(function(event) {
          event.preventDefault();
          $('dialogid')
            .data('image_id', $(this).data('id'))
            .dialog('open');
       })
    })
    

    the image id from the data attribute is then passed to the data attribute of the dialog. This attribute can be accessed using $(this).data('image_id') form within the dialog then

提交回复
热议问题