Я не знаю, если это именно то, что вы хотели, но это то, что я понял из вашего объяснения:
var from = "";
var to = "";
$("td").click(function(){ // fires when you click on a td element. You could also use $(".some_class") for example
if(from=="") { // if "from" is still empty
from = $(this).attr('id'); // define as id of this element
} else if(from!="") { // if "from" is already filled
to = $(this).attr('id');
$.post("/file.php", { firstvar: from, secondvar: to } ); // posts variables "from" and "to" as "firstvar" and "secondvar"
from = ""; // reset the variables
to = "";
}
});
Вы не сказали, когда данные должны получить пост, поэтому я написалэто в другом, так как я думаю, что вы хотите опубликовать его тогда ..
В file.php вы можете получить данные как $_POST["firstvar"]
и $_POST["secondvar"]
Вы также можете использовать $.ajax()
вместо $.post
$.ajax({
type: 'POST',
url: '/file.php',
data: { firstvar: from, secondvar: to },
cache: false,
success: function(data) {
// the output of this file was saved in "data"
// something you want to do on success
},
error: function(xhr, ajaxOptions, thrownError){
alert('there was an error');
}
});