Custom API handler problem

I’m trying to follow Example 4 in ‘Ajax by API and Client Scripts’. (v2020)When the user sets a particular drop-down field on the ‘Add’ page, I want my code to lookup and check something and then issue an alert warning.Server Global code is$API_ACTIONS[“getFAC”] = function(Request $request, Response $response) {
$membId = Param(“MembID”); // Get the input value from $GET or $POST
if ($membId !== NULL)
Write(ExecuteScalar(“SELECT fac_no FROM members WHERE ID = " . AdjustSql($membId))); // Output field value as string};It should just look up the text field fac_no for the provided id and return it.The field used for lookup is mname-id and the Add page Startup Script is…$(”#x_mname-id").change(function() {
var url = ew.API_URL, action = “getFAC”, id = encodeURIComponent($(this).val());
//$.get(url + “/” + action + “MembID=” + id, function(res) { // URL format if URL Rewrite enabled
$.get(url + “?action=” + action + “&MembID=” + id, function(res) { // Get response from custom API action
if (res)
ew.alert(val(res)); // Set the result (manipulate it first if necessary) to the target field
});});Nothing happens when you change the drop-down field mname-id and there are no obvious error messages.
Any idea where I’m going wrong?
Thanks

You may press F12 and click Network to check the network response from the API first.

Thanks. No network response when I make a selection on the drop-down mname-id
(Normal network responses on page loading, etc.)
Steve

A little progress. Realised that the field name mname-id gets given an css id of x_mname_id. Hadn’t realised the dash gets changed to an underscore.
After correcting that, network shows the correct activity with a url call of…localhost/lsrpc/api/index.php?action=getFAC&MembID=27&token=…No pop up alert appears but something happens because the cursor remain as a circle until I leave that page.The SQL statement in the global code - ExecuteScalar(“SELECT fac_no FROM members WHERE ID = " . $membId) - is correct and produces a result when plugged into the database so I guess my error must lie somewhere back in this script:$(”#x_mname_id").change(function() {
var url = ew.API_URL, action = “getFAC”, id = encodeURIComponent($(this).val());
//$.get(url + “/” + action + “MembID=” + id, function(res) { // URL format if URL Rewrite enabled
$.get(url + “?action=” + action + “&MembID=” + id, function(res) { // Get response from custom API action
if (res)
ew.alert(val(res)); // Set the result (manipulate it first if necessary) to the target field
});
});Steve

To debug your codes, press F12 → Source, navigate to the JavaScript codes and add a break point.