Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4622152
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:12+00:00 2026-05-22T02:48:12+00:00

I have an API that is available only in javascript (no PHP). It fetches

  • 0

I have an API that is available only in javascript (no PHP). It fetches some data of which I made a JSON string. What I need to know is how do I read this string in other page?

I tried using following :

$json = file_get_contents($url);

but of course the string I get is not JSON but is actually the javascript code that will generate json in original page. Any suggestions ?
Thank you.

P.S. I also tried set cookie + redirect. Though that worked, I’d like to know a better solution.

Here is the javascript code

            function searchComplete() {

                 if (imageSearch.results && imageSearch.results.length > 0)
                 {
                    var contentDiv = document.getElementById('content');
                    contentDiv.innerHTML = '';
                    var results = imageSearch.results;

                    var data = "{['data' : [\n";

                    for (var i = 0; i < results.length; i++) {
                        //var result = results[i];
                        var result = results[i];

                        data += "{\n";
                        data += "'url' : '"+result.url+"'";
                        data += "\n},\n";

                   }
                   data += "]]}";
                   setCookie("datajson", data, 1); // This is how i set the cookie and redirected
                   window.location = "JSPHP.php?data="+data;

                document.getElementById('body').innerHTML = data;
                  }
            }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:48:13+00:00Added an answer on May 22, 2026 at 2:48 am

    Ok, you said it is not JSON. Thus json_decode() function is useless here without additional things. If this happens on browser side, you should probably pass the data to the server using AJAX.

    Alternatively you can take a look how this API works (maybe it connects with some server using JSONs to exchange data?) and do the same in PHP.

    EDIT:

    You do not need to create a string of JSON on JavaScript side. JSON is itself object notation in JavaScript.

    If you need to pass the data, just do something similar to this:

    var data = [];
    for (var i=0; i<results.length; i++){
        data[] = {
            'url': result.url
        };
    }
    

    Then you only need to pass this data to the server. You can use .get() function (if you need to pass it using GET) from jQuery like that:

    jQuery.get('http://example.com/', data, function(){
        // something to do when successful
    });
    

    It is pretty simple and the basic is: create data correctly and pass it to the server using AJAX call.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Kdiff3 have APIs available? Or is there any comparison tool's API available that
So, I have an API that I need to implement in to an existing
I have a need to create a transactional process using an external API that
I have an API DLL that several third party applications reference. Some of these
Have you ever looked for a web API for certain data or functionality, only
I have an API that is dependent on certain state information between requests. As
I have an API that can be implemented by various vendors. I can send
So Google Analytics does not have an API that we can use to get
I'm developing a REST api. To simplify my question, I have an API that
I have a web API that returns python dictionaries or lists as a response

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.