Having this code snippet which, as you know (already if you read previous posts) or can see now it gets the id from a link and sends it to a sql php script which is then loaded from a div. Fine.
Now, because it turns out that I am using that script for several tables and I have added that it should also go to another page I am then adding what I think is right observing what I have learned from the first example, I add another parameter to the snippet and to the link. So I post the first snippet and then what I added myself after having seen the documentation about JQUERY get function.
THIS IS THE FIRST SNIPPET
<script type="text/javascript">
$(document).ready(function(){
$('a.flip').live('click',function(){
$(".panel").slideToggle("slow");
$('#reviews').load('SendIdToDatabase.php', {id_cruise: this.id});
});
});
</script>
and like I said, I want to add another parameter (namely the table name) and send the same to another script so:
<script type="text/javascript">
$(document).ready(function(){
$('a.flip').live('click',function(){
$(".panel").slideToggle("slow");
$('#reviews').load('SendIdToDatabase.php', {id_cruise: this.id, table_name:this.table});
$('Submitform.php').load('Submitform.php', {id_cruise: this.id, table_name:this.table});
});
});
</script>
Note in this second snippet that the value to the submitform is "thrown in" to a whole page, (unlike in the case of #reviews where it landed specifically in an anchor), so I dont know if that is the way you write it when you send it to just a page.
AND THIS IS THE ORIGINAL LINK LINE
$sOutput .= '"<a href=\"#\"' .' id=\"' .addslashes($aRow['id_ship']) .'\" class=\"flip\">'.addslashes($aRow['name_ship']).'</a>",';
AND THIS IS HOW IT WOULD BE IF I WANT TO ADD THAT PARAMETER FOR THE NEW SNIPPET
$sOutput .= '"<a href=\"#\"' .' id=\"' .addslashes($aRow['id_ship']) .'\" . table=\"ships\" . class=\"flip\">'.addslashes($aRow['name_ta']).'</a>",';
What I have added is the table = ships, I think I have done it right with dots and quotes
So, this is all basically. What I wanted is that aside from the ID being passed, also the name of the table is passed, in this case, ship
UPDATE
I have an alternative code that makes my frail intellect understand it.
$sOutput .= '"<a href=\"#\"' .' id=\"' .addslashes($aRow['id']) .'\" class=\"flip\" rel=\"'.$tablename.'\">'.addslashes($aRow['event_name_cont']).'</a>",';
This looks fine to me in the sense that for every page I can assign anywhere in the page that attribute written in bold letters and send it away on clicking. How does that sound to you ? Correct ?
And then in order to fetch AND forward that value, would this do ?
$('#reviews').load('SendIdToDatabase.php', {idx: this.id, attr("rel") 开发者_StackOverflow中文版});
UPDATE OF THE UPDATE
Ok got it. This is the code that works
$('#reviews').load('SendIdToDatabase.php', {idx: this.id, tabla: $(this).attr("rel")});
So, what I learned here (sorry about my ridiculous beginning level) is that not all parameters are equal, when it comes to how to fetch them or put them on the link. As my helper expressed, whether it is a DOM element or an attribute or anything else matters.
Yes there is something wrong, table
isn't a DOM property, it's an attribute you've added, so this:
$('#reviews').load('SendIdToDatabase.php',
{id_cruise: this.id, table_name: this.table});
Should be:
$('#reviews').load('SendIdToDatabase.php',
{id_cruise: this.id, table_name: $(this).attr("table")});
But...since it's an invalid attribute anyway, I'd use data-
attribute which will at least be valid in HTML5+, which means data-table="ships"
instead of table="ships"
in your anchor, then you can do this in jQuery 1.4.3+
$('#reviews').load('SendIdToDatabase.php',
{id_cruise: this.id, table_name: $(this).data("table")});
....or this in older jQuery versions (also in jQuery 1.4.3+):
$('#reviews').load('SendIdToDatabase.php',
{id_cruise: this.id, table_name: $(this).attr("data-table")});
well, my question is posted in the updates I wrote. Basically this code did the trick for the LINK
$sOutput .= '"<a href=\"#\"' .' id=\"' .addslashes($aRow['id']) .'\" class=\"flip\" rel=\"'.$tablename.'\">'.addslashes($aRow['event_name_cont']).'</a>",';
And this code did the other trick for the JQUERY snippet in order to fetch that attribute
$('#reviews').load('SendIdToDatabase.php', {idx: this.id, tabla: $(this).attr("rel")});
I always deeply appreciate all help and hints, thank you to all those who posted them.
best regards
Alvaro
精彩评论