Forums de discussion

Javascript: "undefined" return first time accessing function

thumbnail
Marco Rosetti, modifié il y a 9 années.

Javascript: "undefined" return first time accessing function

Junior Member Publications: 68 Date d'inscription: 06/03/13 Publications récentes
Hi,
I'm facing a problem accessing a javascript function.
Using the code above, first time (after page load) I click on TEST button I get message "Help: undefined" while other times I get the correct "Help: test liferay provide"

This problem does not occurs if I use a standard javascript function declaration (without using Liferay.provide method).

<aui:script use="aui-base">
Liferay.provide(
	window,
	'<portlet:namespace />MYFUNCTION',
	function()
	{
		return 'test liferay provide';
	}
)
</aui:script>

&lt;%
	String command = "javascript: alert('Hellp: '+"+namespace+"MYFUNCTION())";
%&gt;
<aui:button value="TEST" onClick="<%=command %>" />


Am I doing something wrong? Or missing something?

Thanks in advance,

-MR
thumbnail
Mohammad Azharuddin, modifié il y a 8 années.

RE: Javascript: "undefined" return first time accessing function

Expert Publications: 492 Date d'inscription: 17/09/12 Publications récentes
Facing Same problem..Is this a BUG..?
Govinda N, modifié il y a 8 années.

RE: Javascript: "undefined" return first time accessing function

Junior Member Publications: 28 Date d'inscription: 02/04/14 Publications récentes
Liferay.provide() is an asynchronous function and the JS functions created with this Liferay.provide() can't return a value.
That's the reason it shows 'undefined'

Check this for more info
https://issues.liferay.com/browse/LPS-9371