不使用表单操作调用PHP文件

I am new to php. I did a little search but did not find a good solution. So posting the question here.

I have several thumbnail images in my webpage. Something like:

 <img src="" id="thumb1">
 <img src="" id="thumb2">
 <img src="" id="thumb3">
 <img src="" id="thumb4">

I want to call load a php file when a user clicks on any of these thumbnail images and pass the id of the image to the php file. This php file queries the database with the image id and displays the relevant information. So far I used "form action" to call a php file.

Can you please tell me how to call php file and pass the image id?

Thanks.

You can post to a script without using a form, here is a simple example

$.post("get_image.php", { thumbId: thumb1 },  function(response) {
  console.log(response); 
});

And in php side $_POST['thumbId']

If you are using jQuery try this:

var get_thumb_details = function(thumb_id) {
    $.ajax({
        type: "POST",
        url:  "process_image.php",
        data: {
            thumb_id: thumb_id
        }
    })
    .done(function( data) {
        // This is the data received from the server
        console.log(data);
    }); 
};

// Attach onclick event on your images
$('img').on('click', function() {
    var thumb_id = $(this).attr('id');
    get_image_details(thumb_id);
});

On the server side you can access the request parameters using the $_POST object.

$input_thumb_id = $_POST['thumb_id'];
var_dump($input_thumb_id); // if you want to check the variable value

Use links:

<a href="php_file.php?id=thumb1"><img src="" id="thumb1"></a>
<a href="php_file.php?id=thumb2"><img src="" id="thumb2">/a>
<a href="php_file.php?id=thumb3"><img src="" id="thumb3">/a>
<a href="php_file.php?id=thumb4"><img src="" id="thumb4">/a>

php side: $_GET['id'];

You can try Angualr Js. In angular js we can the get the form elements attributes without submitting. So you can get the image id's on clicking using angular js. You can pass the same to get your required php page.