0

I am not familiar with jquery and javascript, I was wondering how to set the base url of my site in an external js file.

This is the example code:

"use strict";
function savelike(post_id) {
  $.ajax({
    type: "POST",
    url: "main/savelikes",
    data: "post_id=" + post_id,
    success: function(response) {
      $("#like_" + post_id).html(response + "");
    }
  });
}
Dev
  • 1,592
  • 2
  • 22
  • 45
  • Didn't understand the question; what should happen when? – Akxe Mar 07 '20 at 16:35
  • How can I set the website url address here "url: "main/savelikes""? –  Mar 07 '20 at 16:39
  • Is this what you need? https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page – Akxe Mar 07 '20 at 16:55
  • No, I need to set the site url to an external js file. I only need it because otherwise the path for the function in the controller will not work. –  Mar 07 '20 at 16:57
  • Setting URL to external file will open it... you don't want the user to read your JS file, not intentionally. Do you mean you want to import some external JS file? – Akxe Mar 07 '20 at 17:02

0 Answers0