Need Help - href in PHP to pass two array variables to AJAX and return new PHP array

PHP code below. As you know onClick doesn’t work, client side. I would like to use AJAX but not familiar with to display a “div” below list of images

	   <ul>
		<?php
		

		/*************************************
		* Get company items
		*************************************/
		
		$company_items_array = $hd->view_items_by_company($company_id,$db);

//var_dump($company_items_array);

		$count = count($company_items_array);
			for($i = 0; $i < $count ; $i++) {
			

		        echo "<li><a class='view_item' href='#' ".$company_items_array[$i]['item_number']."><img src='images/".$company_items_array[$i]['item_number']."-1_nav.jpg' alt='".$company_items_array[$i]['title']."' width='96' height='86' class='pic-fix'/></a></li>";


		} ?>			
		
		</ul>

Here’s the PHP array to return:

		 $company_item_array = $hd->view_item_by_company($item_number,$company_name,$db);

To populate “div”

Does anyone have a suggestion or code examples? Perhaps a good book on AJAX, too? Thanks!

Probably the best way to do it in this circumstance would be to have your href element link to a working page. Doing this would make the page and links works correctly for visitors without javascript enabled as well. You could then use jQuery’s .load() function to cherry pick the content for users who have javascript enabled.

Assuming you want to load the result into a div with the class of ‘item_data’.


// this will capture any click event on an item with the class
// of view_item
$('.view_item').click(function(e) {

    // 'e' refers the click event itself and peventDefault() will
    // stop the browser executing it's default action and loading the page
    e.preventDefault();

    // 'this' refers to the element which was clicked.
    // The .attr() method will retrieve the value of the 'href' element.
    var url = $(this).attr('href');


    // fetch all of the html content from your target url that is within
    // the element with id item_information and load it into your
    // item_data container on the current page.
    $('#item_data').load(url + ' #item_information');
});

If your interested in learning jQuery/javascript I highly recommend Codecademy. If you want to learn to make an actual Ajax call to retrieve json or xml you could start [URL=“http://api.jquery.com/jQuery.ajax/”]here, and there are a thousand other resources out there.