I'd like to pass addition POST values below in addition to the 'page' variable that is already in the jquery below. What is the most efficient way of adding these? Thanks

$_POST['cat']
$_POST['testid']
<script type="text/javascript">
$(document).ready(function() {
	$("#results" ).load( "/get_pages.php"); //load initial records
	$("#results").on( "click", ".pagination a", function (e){
		e.preventDefault();
		$(".loading-div").show(); //show loading element
		var page = $(this).attr("data-page"); //get page number from link
		$("#results").load("/get_pages.php",{"page":page}, function(){ //get content from PHP page
			$(".loading-div").hide(); //once done, hide loading element
		});
		});
});
</script>
<div id="results"></div>

Well, presumably you're talking about adding things to the {"page":page} bit.

    Do I need to associate a var and assign it to a div element before passing post variables to {"page":page} ?

      What do you mean by "post variable"? Where are you getting your cat and testid values from?

        I am getting the ids from the search_results.php page. I modified it to the following to include $POST[cat] but still having troubles.

        <script type="text/javascript">
        $(document).ready(function() {
        	$("#results" ).load( "/search_results.php?k=<?echo $_GET[k];?>"); //load initial records
        	$("#results").on( "click", ".pagination a", function (e){
        		e.preventDefault();
        		$(".loading-div").show(); //show loading element
        		var page = $(this).attr("data-page"); //get page number from link
        		cat = $("#cat").val(); 
        		$("#results").load("/search_results.php?k=<?echo $_GET[k];?>",{"page":page,"cat":cat}, function(){ //get content from PHP page
        			$(".loading-div").hide(); //once done, hide loading element
        		});
        		});
        });
        </script>
        
        

          Is the file you just posted a .php file or a .js file? If it's php you should be getting errors as short opening tags have been deprecated or removed for many, many years by now. And if it's js, the php isn't getting parsed. Better bet is to inject 'k' into the markup as a hidden input via php, then get that value via js before posting through jQuery.

            Write a Reply...