[RESOLVED] Passing concatenated variables via get and javascript
I have a concatenated list of posts like this:
Code:
<?php
// this generates a list of divs with unique id's as $post_id's
$my_posts .= '
<div class="storypost' . $post_id . '">
<a href="mystorypost.php?id=' . $post_id . '>' . $member_name . ' Post</a>
<a href="#" onclick="DoAction(' . $mem_id . ', ' . $post_id . ');">Remove?</a>
</div>
';
?>
And here is the javascript/ajax, which sends the variables to the _removepost.php, in order to run that code, and delete the post from the database...
Code:
<script>
function DoAction(mem_id, post_id) {
var r = confirm('Are you sure you want to remove this post?');
if (r == true) {
$.ajax({
type: "GET",
url: "_removepost.php",
data: "mem_id=" + mem_id + "&post_id=" + post_id,
});
$(".storypost"+post_id).hide();
return false;
} else {
return;
}
}
</script>
So, the thing actually works (the post gets deleted from the database). But what does not work, is:
1) the div is not getting hidden via the .hide()
2) after I click the onClick link, the page scrolls back to the top of the page... and I have to end up reloading the page to see the change.
I believe there is something wrong with where I placed the "return false;" and something wrong with how I call the variable in .hide().
some browsers (hello IE!) read that as meaning the object has more properties, then get confused when there are not.
So, maybe if you fix those two things your other problem will magically disappear (I doubt it, but it's worth a try).
Not that it will make any difference, but if all the classes you are creating are unique, you could just be using id's... not that it makes much difference, just that id's have to be unique whereas classes can be shared (or unique):
Bookmarks