Вопрос

I am trying to pass a PHP GET variable to AJAX so the appropriate content according to the ID passed can be loaded on the same page but I don't know how to do it exactly. The ID is dynamically generated by a loop and the ID is given in the image hyperlinks below. So basically when they click on an image containing the link and the id that it is passed on, new content will load on the same page.

Below is the code.

<div id="myDiv">
  <h2>Let AJAX change this text</h2>
Это было полезно?

Решение

You want to use the global $_GET variable.

Example:

www.some-url.com/script.php?id=1337

and in the script to access it:

echo $_GET['id']
> 1337

Другие советы

try to put parameter in the function you called...

onclick='loadXMLDoc(".$row['ID'].")'

or you can put the $row['ID'] in the input and set as hidden, then retrieve the value using ajax.

<input type="hidden" value="<?php echo $row['ID']; ?>" id="someid" />

retrieve

var ID = $('#someid').val();
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top