Ajax call in external JavaScript file is not working in Struts2

I am developing Struts2 web application. There is a common value (ex. URL) that used in several JSP pages and I get those values to a external JavaScript file as below.

a.js

var test;
function init() {
  
    $.ajax({
       url: "getStringData.action",
       type: 'GET',
       async : true,
       success: function(response) {
            test = response;
            alert(response);
        }
    });
}

init();

This is my jsp page.

b.jsp

  <script type="text/javascript" src="a.js"></script>

  var value = test;

test is the value that get from imported a.js file.

Struts.xml

<action name="getStringData" class="com.projectName.action.SampleAction" method="getStringData">
<result>/b.jsp</result>
<result name="error">/error.jsp</result>

SampleAction.java

public String getStringData(){
  String dataValue = "sample string value";
  return dataValue;
} 

Ajax function is not working. How can I fix it.