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

  • Home
  • SEARCH
  • 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 9176103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:01:36+00:00 2026-06-17T17:01:36+00:00

What I am trying to do is retrieve JSON data from an online web

  • 0

What I am trying to do is retrieve JSON data from an online web service that searches and finds a certain string in a MySQL database and display it using Javascript on an HTML page.

What I am struggling with is actually displaying the resulting data.

The relevant areas of my HTML page looks like this:

<form onSubmit="results()">
    <fieldset>
        <label for="area">First digits of postal code:</label>
        <input name="area" type="text" maxlength="4" placeholder="AB12" required />
        <input type="submit" value="Search" name="search" />
    </fieldset>
</form>



<script type="text/javascript" src="jquery/jquery.min.js"></script>
<script type="text/javascript" src="cordova-2.3.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">

function results(){
    $.ajax({
        url: 'http://www.foobar.com/cp/index.php?area=AB12',
        dataType: 'jsonp',
        jsonp: 'jsoncallback',
        timeout: 5000,
        success: function(data, status){
            $.each(data, function(i,item){
                var place = '<h1>'+item.location+'</h1>'
                + '<p>'+item.id+'</br>';

                output.append(place);
            });
        },
        error: function(){
            output.text('There was an error loading the data.');
        }
    });
};
</script>

<div id="place">
<h3>Places near your location</h3>
</div>

The page for the GET data is http://www.foobar.com/cp/index.php with the search variable ‘area’. Test sample is ?area=AB12.

  • 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-06-17T17:01:37+00:00Added an answer on June 17, 2026 at 5:01 pm

    It seems that this service is not correctly wrapping the JSON object in parentheses so it doesn’t work as JSONP.

    See: http://www.entertainmentcocktail.com/cp/index.php?area=AB12&jsoncallback=TEST

    It returns:

    TEST[{"id":"5","name":"The Red Lion", ... ,"confirmed":"0"}]
    

    while it should return:

    TEST([{"id":"5","name":"The Red Lion", ... ,"confirmed":"0"}]);
    

    You won’t be able to use it because it is not valid JSONP.

    UPDATE:

    Answering more info from the comment – if you control the server-side script then try changing:

    while($row = mysql_fetch_assoc($result)) { $records[] = $row; }
    echo $_GET['jsoncallback'] . json_encode($records);
    

    to:

    while($row = mysql_fetch_assoc($result)) { $records[] = $row; }
    echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
    

    and see if that works.

    UPDATE 2:

    Answering another comment. Do you actually initialize the output variable? For example with something like this at the beginning:

    var output = $('#place').append('<div/>');
    

    Do you actually call your results function? It must be called with:

    results();
    

    or registered somewhere as an event handler, using the jQuery way:

    $('form').submit(results);
    

    but then add:

    return false;
    

    to the end of the results function to prevent the page from being reloaded.

    See this demo: http://jsbin.com/uziyek/1/edit – it seems to work.

    Another problem:

    There seems to be another problem with your code, that the area=AB12 parameter is hardcoded into your URL. What you should do instead is get the value from the form and send that.

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

Sidebar

Related Questions

I am trying to retrieve a JSON file from a web service using the
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve data with JSON from my database and parse them
I am trying to display JSON data that I retrieve from an ajax call
I am trying to learn how to retrieve data from a json obj that
I'm trying to retrieve data from a JSON object that looks like this: stdClass
I am trying to figure out how to retrieve data from a MySQL database
I'm trying to retrieve product information from magento by calling its web service using
I am trying to retrieve JSON data from an external text file using a
I'm trying to retrieve JSON data from a remote site with Rails/Prototype. I've found

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.