4 Replies Latest reply on Aug 8, 2014 12:52 PM by Ryan Rutan

    ajax cross domain for Jive api v3

    tehras

      Hi,

      My current code is this:

       

      $.getJSON("https://www.domain.org/api/core/v3/contents?callback=?",

          function(data){

            $.each(data, function(i,item){           

              alert(item.x);

            });

        });

       

      The only problem I get is that I have:

      throw 'allowIllegalResourceCall is false.'; which causes an error, How can I cut this line out in javascript?

        • Re: ajax cross domain for Jive api v3
          tone

          Hi Taras,

           

          You may have already seen this, but the throw string is explained in detail in What is the purpose of the JSON Security String?

           

          An example of its removal using a regular expression (in Python) can be found here Jive REST Rest API v3.7

           

          In jQuery, you can use a regular expression to clean out that line in the "dataFilter" setting in an $.ajax or $.ajaxSetup call.

           

          -Tone

            • Re: ajax cross domain for Jive api v3
              tehras

              That's what i thought I can do, but when i did dataFilter: function(data, type){}, the type would come in as jsonp, but the data was undefined, I might have to play around with it a little, more, this seems like a good answer though.

                • Re: ajax cross domain for Jive api v3
                  pawans

                  I have a node.js app and also a python script which call the jive rest apis.

                  Here's small code snippet I have in both these to clean the jive response

                  This might help you write a code for your case

                   

                  In node.js app

                  request(getUserRequest, function (error, response, body) {

                         userData = JSON.parse(body.replace(/throw.*;/, "").trim())

                          ...

                  });

                  You will have to write a client side version similar to this

                   

                  Here's the code I wrote in my python scripts to clean this

                   

                  import re

                  import json

                  jive_response = re.sub('\A.*[;]', "", jive_response.text).encode('utf8', 'ignore')

                  json_response = json.loads(jive_response)

                    • Re: ajax cross domain for Jive api v3
                      Ryan Rutan

                      Similarly, if the response was successful, I do a simple substring that keys off of the position of the 1st { character.  Also, if jQuery doesn't like the format of json, you can specify return type text, and do a JSON.parse similar to the way Pawan showed to get a proper JSON object.