Jul 08
Javascript function parameter issue : Uncaught SyntaxError: Unexpected token = in Google Chrome
In Javascript, we often use functions for common tasks. Recently I have fallen in a problem where i have written a function to get ajax call which is common for some actions. That function has a parameter to get the URL which needed for ajax call. It was ok in Firefox, but in chrome, all other JS work stopped, due to the parameter error, that is ‘parameter default value’. Solution is, you can’t assign a default value to the function parameter. More explanation here: Function default parameter.
So we need to use below way for browser compatibility:
function get_ajax_fields(parameter){
flds_request = jQuery.ajax({
url: baseURL+"dataimport/"+parameter
,
dataType: "json"
});
return flds_request;
}
We can't use like this: parameter=''
Hope the issue can save your time! Enjoy!!