Ok, this is my final tango with this. Below I've listed the code. I'm able to get the value of the url and display it on screen for the current (active tab) in Google Chrome. Now all I have to do is pass that value as a parameter in the URL via JSON. My processing file resides on a our remote server - in php. Everything I've done with respect to this has worked to perfection. However, any attempts to pass the current url or any url as one of the parameters - e.g. ?format=json&url=http://something.com&callback=? - results in nothing. I'm not sure if what I'm doing is wrong or if it is even possible. The important thing to note is that all we are looking to do is pass the url to a remote server for storage, processing etc and send back results. I have everything working but I just can't seem to get the url to pass as a parameter.

<html>
  <head>
    <title>API JSON Test</title>
    <script type="text/javascript"  
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script>
        window.addEventListener("load", windowLoaded, false);
        function windowLoaded() {
          chrome.tabs.getSelected(null, function(tab) {
            document.getElementById('currentLink').innerHTML = tab.url;
          });
        }
    </script>

    <script type="text/javascript">

        $(document).ready(function(){

   var timeService =
       "http://api.ulore.com/api2.php?key=abce&url="+tab.url+"&format=json&callback=?";


    $.getJSON(timeService, function(data) {
    $('#showdata').html("<p>url_results="+data.post.url+"</p>");
              });
        });
    </script>
        <div id="showdata"></div>
</head>
<body>

</body>
</html>

Again, all the JSON works fine when I'm testing other code. Even if I put in a NON-URL value as a parameter for url=..... it throws the appropriate error. However, it will not accept a URL for some reason.

Any feedback will be greatly appreciated.

Thanks, Ethan-Anthony

I thought callback=? was associated with jsonp, not json.

Hi Airshow,

I apologize for any confusion caused by the title. I mentioned JSONP because I'm doing cross-domain scripting.

OK, don't apologize, my bad. I forgot that the presence of callback=? gives .getJSON() JSONP behaviour.

Have you remembered to wrap your json response in a function call, eg.:

echo $_GET['callback'] . '(' . json_encode(.....) . ');'

Airshow

That's probably a silly question if it's a third party server.

On the other hand, are you certain that the server is set up to return jsonp (with the function call wrapper), not json. After all, the request asks for format=json , not format=jsonp .

Ok, this is my final tango with this. Below I've listed the code. I'm able to get the value of the url and display it on screen for the current (active tab) in Google Chrome. Now all I have to do is pass that value as a parameter in the URL via JSON. My processing file resides on a our remote server - in php. Everything I've done with respect to this has worked to perfection. However, any attempts to pass the current url or any url as one of the parameters - e.g. ?format=json&url=http://something.com&callback=? - results in nothing. I'm not sure if what I'm doing is wrong or if it is even possible. The important thing to note is that all we are looking to do is pass the url to a remote server for storage, processing etc and send back results. I have everything working but I just can't seem to get the url to pass as a parameter.

<html>
  <head>
    <title>API JSON Test</title>
    <script type="text/javascript"  
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
    <script>
        window.addEventListener("load", windowLoaded, false);
        function windowLoaded() {
          chrome.tabs.getSelected(null, function(tab) {
            document.getElementById('currentLink').innerHTML = tab.url;
          });
        }
    </script>

    <script type="text/javascript">

        $(document).ready(function(){

   var timeService =
       "http://api.ulore.com/api2.php?key=abce&url="+tab.url+"&format=json&callback=?";


    $.getJSON(timeService, function(data) {
    $('#showdata').html("<p>url_results="+data.post.url+"</p>");
              });
        });
    </script>
        <div id="showdata"></div>
</head>
<body>

</body>
</html>

Again, all the JSON works fine when I'm testing other code. Even if I put in a NON-URL value as a parameter for url=..... it throws the appropriate error. However, it will not accept a URL for some reason.

Any feedback will be greatly appreciated.

Thanks, Ethan-Anthony

As always, you'll first need to encode it.

to be more precise:

escape(timeService)//or whatever you are putting there, -and 
unescape(it)  //when needed

you may want to read and expand your knowledge further on, in: encode/decodeURI and encode/decodeURIComponent functions also.
Regards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.