0

I am getting error - TypeError: updateAPI is not a functionn I am not sure why this is happening

the code for the function is as below

var APIS = '<?=preg_replace("/'/", "\'", json_encode($apis))?>';
var APISP = $.parseJSON(APIS);

var changedTo = 'left';
var updateAPI = function(id)
{
    /* Function Statements */
};

The code through which I am calling this function is

window.setInterval(function() {
var ele = document.getElementById('itemSelector');
updateAPI((ele.options[ele.selectedIndex].id).replace(/[_\D]+/, ''));
}, 100);

Can anybody help? Thanks in advance.

1 Answer 1

1

Your use of escape character is wrong. It is evident even after seeing the formatting of your question done by StackOverflow. You have used forward slash (/) instead of backward slash (\). Hence, var updateAPI is included in that string and updateAPI is undefined.
Try this:

var APIS = '<?=preg_replace("\'/", "\'", json_encode($apis))?>';

OR maybe depending on what regular expression you want, you might want this:

var APIS = '<?=preg_replace("/\'/", "\'", json_encode($apis))?>';
Sign up to request clarification or add additional context in comments.

Comments

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.