Reputation: 873
Having trouble getting success from this...
<!-- Ajax -->
<script type="text/javascript">
$('a.clickup').click(function (event) {
event.preventDefault();
$.ajax({
type: 'get',
url: "actions.php",
data: "action=10&moveMe=<?php echo $row_rsChkOptions['chkID'] ?>&startPos=<?php echo $row_rsChkOptions['orderID'] ?>&parentCategory=<?php echo $row_rsChkOptions['categoryID'] ?>&chklistID=<?php echo $row_rsChkOptions['chklistID'] ?>"
success: function (data) {
alert('success');
}
});
</script>
Normally, when I would just want the page to reload, I would set the href
to:
actions.php?action=10&moveMe=<?php echo $row_rsChkOptions['chkID'] ?>&startPos=<?php echo $row_rsChkOptions['orderID'] ?>&parentCategory=<?php echo $row_rsChkOptions['categoryID'] ?>&chklistID=<?php echo $row_rsChkOptions['chklistID'] ?>
});
What am I doing wrong here? I am not getting my success alert.
Upvotes: 0
Views: 3682
Reputation: 956
One problem could be that you have not wrapped your code in a jQuery load function, such as this:
<script type="text/javascript">
$(function () {
$('a.clickup').click(function (event) {
event.preventDefault();
var data = "action=10&moveMe=<?php echo $row_rsChkOptions['chkID'] ?>&startPos=<?php echo $row_rsChkOptions['orderID'] ?>&parentCategory=<?php echo $row_rsChkOptions['categoryID'] ?>&chklistID=<?php echo $row_rsChkOptions['chklistID'] ?>";
$.get("actions.php", data, function (data) {
alert('success');
});
});
});
</script>
This reason I suggest this is that trying to apply a click function handler on a DOM element when the DOM element hasn't fully loaded by the browser can cause problems. Wrapping your code in a jQuery load function such as this will take care of that problem if that is indeed what is happening. I also took the liberty of rewriting your $.ajax function call to make it a little easier on the eyes. But that is purely subjective!!
Upvotes: 1