0

I have a script like this:

<script type="text/javascript">
function DeletePublisher(publisherid) {
jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) { if (r)

scriptitem = document.createElement('script');
scriptitem.type = 'text/javascript';
scriptitem.src = 'includes/publishers/delete-publisher.php?publisherid=' + publisherid;
scriptitem.id = 'ajax';
document.body.appendChild(scriptitem);
setTimeout('document.body.removeChild(document.getElementById("ajax"))', 500);  

$.jGrowl('Publisher deleted');
window.location.reload();
});
}
</script>

And I am listing rows in table like this:

TD ROWS HERE...
<td class="unpaid-th"><strong><?php echo $publisher_unpaid; ?></strong></td>
                <td class="action-th">
                    <ul class="button-table-head">
                        <li><div class="button-head edit-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Edit" data-style-tooltip="tooltip-mini-slick"><span>Edit</span></a></div></li>
                        <li><div class="button-head delete-icon"><a href="#" class="sweet-tooltip" data-text-tooltip="Delete" data-style-tooltip="tooltip-mini-slick" onclick="DeletePublisher('<?php echo $publisher_id; ?>')"><span>Delete</span></a></div></li>
                    </ul>
                </td>

Now what should happen is when I click on delete link - it should post/get (whatever - as i use $_REQUEST on listener script) to php script that will get the id of publisher and delete it from DB.... But the problem seems to be that no ID is actually send to delete script and I've tried everything....

It displays nice in source code like onclick="DeletePublisher('152')" and prompts alerts, infos etc... but it seems that it's not sending ID..... OR NOW MAYBE NOT EVEN CALLING A LISTENER script (don't know how to test it) :(

Any ideas what's wrong here (or maybe different approach?) ?

Thanks a lot !

2 Answers 2

1

I would recommend using AJAX like below which uses jQuery

function DeletePublisher(publisherid) {
  jConfirm('Are you sure you want to delete this publisher?', 'Delete publisher', function(r) { if (r)
    $.ajax({
      type: "POST", //or GET
      url: 'includes/publishers/delete-publisher.php?publisherid=' + publisherid,
      data: '',
      success: function(response){
        $.jGrowl('Publisher deleted');
        window.location.reload();
      }
    });
  });
}
Sign up to request clarification or add additional context in comments.

Comments

0

I think what you are trying to do is JSONP call. What I think would be missing is that the response should be wrapped inside a javascript call. The name of the method should be same as the callback method.

But I think you need not go ahead with JSNOP aproach as I see your script is on the same domain. So try making a simple ajax call. You can try jquery. It will make take care of browser compatibility.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.