0

I'm new in programing websites so forgive my lack of knowledge... I'd like to load some content from database without reloading page. So using jquery I can load php file which conects with database

 $("body").on("click",".editpages", function(){
    $('#pagesedit').load('/templates/admin/pages.php #edit');
 });

Problem is that I need to send one variable that I can use it in my php file. How can I do that?

2
  • 2
    use query strings http://example.com/pages.php?var=hello, then access thru $_GET['var'] in PHP, # hash doesn't get set in server side Commented Apr 14, 2015 at 12:53
  • You can also use ajax methods for variable passing Commented Apr 14, 2015 at 12:59

2 Answers 2

1

Use Jquery Ajax

 $("body").on("click",".editpages", function(){
  $.post( "templates/admin/pages.php", { yourVariable: "John" })
 .done(function( data ) {
  alert( "Data Loaded: " + data );
 });
});
Sign up to request clarification or add additional context in comments.

Comments

1

Id recommenced looking at PHP Get Varriables. First just pass the varriable to your php page.

$("body").on("click",".editpages", function(){
  $('#pagesedit').load('/templates/admin/pages.php?YOUR_VARIABLE_NAME');
});

<?php
  if isset(htmlspecialchars($_GET["name"])) {
    // DO WHATEVER IN PHP
  }
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.