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 9166377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:08:21+00:00 2026-06-17T15:08:21+00:00

I cannot display jSON data from a url in my browser using this script

  • 0

I cannot display jSON data from a url in my browser using this script but I cannot find the source of the error.

The url (http://www.entertainmentcocktail.com/cp/index.php) contains what I understand is valid jSON data but there is nothing returned when I use this code:

    <script type="text/javascript" src="cordova-2.3.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="jquery/jquery.min.js"></script>
        <script type="text/javascript">
                $(document).ready(function(){
                    var output = $('#output');

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

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

EDIT: The target page with the jSON data generates the information from a database with this code:

<?php
header('Content-type: application/json');

$server = "SERVER";
$username = "USER";
$password = "PASS";
$database = "DB";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

$sql = "SELECT id, name, location FROM table_name ORDER BY id";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) {
    $records[] = $row;
}

mysql_close($con);

echo $_GET['jsoncallback'] . json_encode($records);
?>
  • 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-17T15:08:23+00:00Added an answer on June 17, 2026 at 3:08 pm

    Are you running this code from the same domain (www.entertainmentcocktail.com)? If not, you might be running into a XSRF issue.

    What browser are you using to test? In Chrome you can right click and goto “Inspect Element” which then has a little red mark in the bottom right hand corner if there is a java script error. You should be able to find more information here.

    http://cl.ly/image/261T3T360M34 – Screen shot of errors in bottom right hand corner.

    How are you generating your json string? You should ideally use the built in PHP function:
    http://php.net/manual/en/function.json-encode.php

    Update:

    From your comment, your issue is the ordering if your scripts. Change it to be like this:

    <script type="text/javascript" src="cordova-2.3.0.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript" src="jquery/jquery.min.js"></script>
        <script type="text/javascript">
                $(document).ready(function(){
                    var output = $('#output');
    
                    $.ajax({
                        url: 'http://www.entertainmentcocktail.com/cp/index.php',
                        dataType: 'jsonp',
                        jsonp: 'jsoncallback',
                        timeout: 5000,
                        success: function(data, status){
                            $.each(data, function(i,item){
                                var name = '<h1>'+item.location+'</h1>'
                                + '<p>'+item.id+'</br>';
    
                                output.append(name);
                            });
                        },
                        error: function(){
                            output.text('There was an error loading the data.');
                        }
                    });
                });
                </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display Redis data in the browser using Webdis and jQuery.
I cannot get the returning data from the server to display on my form
I have a JSON response returning from an Ajax call but cannot seem to
I'm having more problem with JSON! I am using the advice from this article
I am using this plugin http://almende.github.com/chap-links-library/js/timeline/doc/ to render a timeline from some JSON data.
I am using DataTables (jQuery plugin) to display my tabular data. If fetches data
Using this tutorial: http://www.codeproject.com/Articles/105273/Create-RESTful-WCF-Service-API-Step-By-Step-Guide I can get a Directory Listing to display when I
I want to pull data from Google's Suggest API and display it in my
using the following feed: http://api.twitter.com/1/statuses/user_timeline.json?screen_name=microsoft&include_rts=1&count=10 I am successfully able to loop through this to
When I get some json data I want to display them in the page

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.