eZ Community » Forums » Developer » ezjscore ajax call

ezjscore ajax call

ezjscore ajax call

Friday 17 February 2012 2:59:31 pm - 4 replies

I've been trying all day to get a simple ajax call using ezjscore to work.  I've hunted extensively through the forums and can't seem to find any examples.  In my javascript I just want to load a set of nodes in json format.  I thought one of the following should work:

$.ez('ezjscnode::subtree::226', {http_accept: 'json'}, function (ezp_data) {
    if (ezp_data.error_text) {
    } else {
        $("#results"blunk.gif Emoticon.append(ezp_data.content);


      url: '/ezjscore/call/ezjscnode::subtree::226?http_accept=json',
       type: 'post',
       data: '',
       dataType: 'json',
       success: function (data, status) {
          $("#results"blunk.gif Emoticon.append(status);
          $("#results"blunk.gif Emoticon.append(data);
      }  });


I'm getting status = success but no data.  The url returns the data fine if I just put it in the address bar.  I'm probably just missing something obvious but it would be great if someone could point it out to me! happy.gif Emoticon  

On a related note, I noticed that the default doesn't return the data map, so I had to make the following change to ezjscajaxcontent.php: 

From: 'dataMap' => array()
To:     'dataMap' => array('all') 

Just wondering why that wasn't set via a parameter in the URL, like ?data_map=all.  Or did I miss something there too?



Friday 17 February 2012 5:16:17 pm

I should add that jquery is giving me a parser error.  I also tried using ggxmlview and still not able to load the data.  Thanks for any ideas.

Friday 17 February 2012 6:54:19 pm

Mmm, ggxmlview is quite a different beast from the ezjscore implementation in ezjscnode::subtree.

Ggxmlview is just a set of templates, so if your current user can view a node X in its html form, he should be able to view it in json form too, via any ajax call made by the browser (no need for jquery in fact, you could build an xhr call by hand).

What type of error are you getting when using it? What url are you using to get at the json view?


On the side of ezjscore, to help with debugging you can try:

- access /ezjscore/call/ezjscnode::subtree::226?http_accept=json from browser. it works for me (using node 2 instead of 226)

- make sure you are logged in as admin, to make sure there is no permission problem

- debug using the ggwebservices console


But if you're getting a js error from jquery, then you know already where the problem is...

Sunday 19 February 2012 10:59:56 am

> I should add that jquery is giving me a parser error.  
As said above, you should look into this one maybe?
 > Just wondering why that wasn't set via a parameter in the URL, like ?data_map=all.  Or did I miss something there too?
Nop, you should probably create your own ezjscore function to modify it. ::subTree does not add the needed datamap logic as ::load for instance does, I assuem the one that added the function did not need it. The way you have currently hacked it, will potentially negatively impact all other ezjscore calls as they all tend to use ezjscajaxcontent.

Thursday 23 February 2012 11:33:34 am

Thanks for the responses!  I managed to get the ezjscore approach working.  I think my mistake was I was trying to append the json to a div to see if it was working but I can't append non html content.  I just wrote the result to the console and was able to see the object returned. The error in using ggxmlview was because ggxmlview was not generating an empty string "" for empty attributes.

@André, you're right, I'll have to create my own ezjscore function.  What is the recommended approach? Can I just override ezjscajaxcontent.php (where the required change is)?  Or do I have to create a new function to replace ezjscorenode (which maps to ezjscserverfunctionsnode.php, which extends ezjscserverfunctions).  

I was thinking of something like: 

In ezjscore.ini.append.php:

# Override of ezjscnode (which maps to ezjscserverfunctionsnode.php, which in turn uses ezjscajaxcontent.php).
# Only one small change was necessary to load the data map.
# In the simplify function of ezjscajaxcontent.php changed 'dataMap' => array() to 'dataMap' => array('all')

Copy ezjscserverfunctionsnode.php to my extension's class folder and change the name to ezjscserverfunctionsnodewithdatamap.php

Copy ezjscajaxcontent.php to my class folder and change the name to ezjscajaxcontentwithdatamap.php

Change the name of the simplify function to simplifywithdatamap and then change the to the simplify function to my new function, simplifywithdatamap. 

Seems like an awful lot of work for a simple change but is that the right approach?




You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from