2

I have this script called admin_order.js, which works fine. Due to a certain plugin which loads ajax content after ajax content has been loaded admin_order.js now doesn't work.

I tried this in the response function but no success.

$.getScript("../../themes/mywebsite/js/admin_order.js");

How do i reload the script?

3
  • So is the admin_order.js modified on the server due to the ajax ca;;s? If not I would investigate further why your script stops working. If yes, then maybe you should restructure your code. Commented Apr 16, 2015 at 13:35
  • No, nothing is modified. The html that the ajax call returns replaces the html that admin_order.js has events attached to but the class names of those elements remain the same.. Any idea? Commented Apr 16, 2015 at 13:38
  • So why don't you query for data only with the ajax call and update the content on the front end? Your current solution partially reloads the page and I guess reloading the page (location.reload();) doesn't work as you end up in the wrong state. Commented Apr 16, 2015 at 13:41

1 Answer 1

2

I think the problem must be handled in another way; but if you can't handle this in the plugin code, you can:

  1. add an id to the script element eg myAdminOrderScript
  2. before the getScript remove the script element
  3. in the getScript success function add an Id to the last script element

Like:

<script id="myAdminOrderScript" src="../../themes/mywebsite/js/admin_order.js"></script>

  function reloadScript() {
    $('#myAdminOrderScript').remove();
    $.getScript("../../themes/mywebsite/js/admin_order.js", function() {
      $('script:last').attr('id', 'myAdminOrderScript');
    });
  }
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, do i put this in the ajax response function?
Yes, or in the getScript (taht is a shortcut of ajax) as the example

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.