after study https://discourse.hkvstore.com/t/ajax-startup-script-to-fill-fields-v2019/2203/1 and Ajax by API and Client Scripts, tried some code from this forums but getting 401 in console, any help? Thanks :)Request URL: http://localhost/school/api/?action=getfeesetup&qno=1&mclassno=1&oldnew=Old
Request Method: GET
Status Code: 401 Unauthorizedin API Action
$API_ACTIONS["getfeesetup"] = function(Request $request, Response $response) {
$mclassno = Param("mclassno"); // Get the input value from $_GET or $_POST
$qno = Param("qno");
$oldnew = Param("oldnew");
if ($mclassno !== NULL && $qno !== NULL && $oldnew !== NULL)
WriteJson(ExecuteRow("SELECT * FROM feesetup WHERE qno = ".AdjustSql($qno)." and mclassno = ".AdjustSql($mclassno)." and groupid = 1" ));
};
in Startup Script
$("#x_regno").change(function() {
//var url = ew.API_URL, action = "getfeesetup", id = encodeURIComponent($(this).val());
var url = ew.API_URL;
var action = "getfeesetup";
var qno = encodeURIComponent($("#x_qno").val());
var mclassno = encodeURIComponent($("#x_mclassno").val());
var oldnew = encodeURIComponent($("#x_oldnew").val());
//$.get(url + "/" + action + "?ProductID=" + id, function(res) { // URL format if URL Rewrite enabled
$.get(url + "?action=" + action +"&qno="+qno+"&mclassno="+mclassno+"&oldnew="+oldnew, function(res) { // Get response from custom API action
if (res){
if (oldnew == "Old"){
$("#x_mctqdue").val(res['mctqfeeo']); // Set the result (manipulate it first if necessary) to the target field
$("#x_mcdue1").val(res['mcfeeo1']);
$("#x_mcdue2").val(res['mcfeeo2']);
}else{
$("#x_mctqdue").val(res['mctqfeen']); // Set the result (manipulate it first if necessary) to the target field
$("#x_mcdue1").val(res['mcfeen1']);
$("#x_mcdue2").val(res['mcfeen2']);
}
}
});
});