0

Sorry silly question. Is it possible to load a page based on an AJAX post? What I'm trying to do is have tabs on my page, with each tab containing different dynamic content updated by user posts. So for example if Tab 1 is clicked I want it to show the posts associated with Tab 1, the same for Tab 2 and so on. I am not at all sure how best to achieve this. I was thinking an onlcick event which send the Tab id to the relevant php file and then returns the results from that file based on the id. Please point me in the direction of a better approach as I'm sure this isn't the best way. Please see code below: index:

$(document).ready(function() {

var id = 1;
var DATA = '&id=' +id;
$.ajax({
type: "POST",
url: "show.php",
data: DATA,
cache: false,
success: function(data){

$(".test").load("show.php");

}

}); 
</script>
</head>
<body>

<div class="test"></div>
</body>
</html>

show.php:

<?php

$id = $_POST['id'];

$me = mysql_query("SELECT * FROM table where id=$id");

while($row=mysql_fetch_array($me)){

$status=$row['status'];



echo $status;
}
?>
Oroku
  • 443
  • 1
  • 3
  • 15
  • 1
    `load()` is a shortand hand method for `$.ajax`. Use one or the other, you don't need both. Read the jQuery API docs which include examples – charlietfl Oct 11 '14 at 13:12

1 Answers1

0

First of all I see that you are using mysql_query, consider moving to mysqli or pdo: The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

Note that your code not filtering mysql injections, if you prefer to stick with mysql you can use: mysql_real_escape_string

Now for your actual question, The best way I think is to achieve this, is to load all the tabs (if we talking about just a few) to variables and store them on the client's RAM using javascirpt (just simply save them on variable) then, whenever the client switch tab, you load it from the variable and that way the client doesn't request it from the server.

Community
  • 1
  • 1
Ido
  • 2,034
  • 1
  • 17
  • 16
  • Thanks very much but I'm still a novice could you give me more specific instruction as to what to do? Sorry for the ignorance – Oroku Oct 11 '14 at 13:39