Thanks a lot Martin. You're right. I had something else in my code and after I fixed it, I managed to make a ajax call from JavaScript.
On Wed, Jan 18, 2017 at 5:07 PM, Martin Grigorov <[email protected]> wrote: > There is no variable named 'a' in your code snippet. > It might be another problem. > > Martin Grigorov > Wicket Training and Consulting > https://twitter.com/mtgrigorov > > On Wed, Jan 18, 2017 at 10:04 AM, James Selvakumar <[email protected]> > wrote: > > > Hi Martin, > > > > I tried your suggestion but I'm still getting the same TypeError. > > > > On Wed, Jan 18, 2017 at 4:55 PM, James Selvakumar <[email protected]> > > wrote: > > > > > Thanks Martin for the super fast reply. I'll try that out. > > > > > > On Wed, Jan 18, 2017 at 4:54 PM, Martin Grigorov <[email protected] > > > > > wrote: > > > > > >> var wcall = Wicket.Ajax.get({ u: '${callbackUrl}'}); > > >> should be > > >> var wcall = Wicket.Ajax.get({ u: window.callbackUrl }); > > >> > > >> Martin Grigorov > > >> Wicket Training and Consulting > > >> https://twitter.com/mtgrigorov > > >> > > >> On Wed, Jan 18, 2017 at 9:51 AM, James Selvakumar < > [email protected]> > > >> wrote: > > >> > > >> > Dear Wicket team, > > >> > > > >> > I need to make a call to a Wicket page from my JavaScript function. > > >> > I followed the guide Calling Wicket from Javascript > > >> > <https://cwiki.apache.org/confluence/display/WICKET/ > > >> > Calling+Wicket+from+Javascript> > > >> > and managed to define an ajax behavior to respond to the JavaScript > > >> call. > > >> > > > >> > My ajax behavior looks like this: > > >> > > > >> > > private final AbstractDefaultAjaxBehavior behave = new > > >> > AbstractDefaultAjaxBehavior() > > >> > > { > > >> > > protected void respond(final AjaxRequestTarget target) > > >> > > { > > >> > > LOGGER.debug("Received a request from client to get the > > >> > encryption key"); > > >> > > target.add(new Label("foo", "Yeah I was just called from > > >> > Javascript!")); > > >> > > } > > >> > > > > >> > > public void renderHead(Component component, IHeaderResponse > > >> response) > > >> > > { > > >> > > super.renderHead(component, response); > > >> > > String callbackUrl = getCallbackUrl().toString(); > > >> > > response.render(JavaScriptHeaderItem.forScript("var > > >> > callbackUrl='" + callbackUrl + "';", "values")); > > >> > > } > > >> > > }; > > >> > > > > >> > > This callback url got rendered in the page like this: > > >> > > > >> > <script id="values" type="text/javascript"> > > >> > > /*<![CDATA[*/ > > >> > > var callbackUrl='./wicket/page?0-1.IBehaviorListener.0-'; > > >> > > /*]]>*/ > > >> > > </script> > > >> > > > > >> > > > >> > > > >> > And here is my JavaScript code: > > >> > > > >> > > var wcall = Wicket.Ajax.get({ u: '${callbackUrl}'}); > > >> > > alert(wcall); > > >> > > > > >> > > But I'm getting the following error in the Wicket Ajax Debug > Window: > > >> > > > >> > *An error occurred while executing Ajax request:TypeError: a is > > >> undefined* > > >> > > > > >> > > > >> > Can someone point out what's the mistake here? > > >> > > > >> > -- > > >> > Thanks & regards > > >> > James > > >> > > > >> > > > > > > > > > > > > -- > > > Thanks & regards > > > James Selvakumar > > > > > > > > > > > -- > > Thanks & regards > > James > > > -- Thanks & regards James
