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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:32:57+00:00 2026-05-28T00:32:57+00:00

I created a php page which print this from the database [{sha_id:2,sha_text:This is 1st

  • 0

I created a php page which print this from the database

[{"sha_id":"2","sha_text":"This is 1st sha."},{"sha_id":"4","sha_text":"this is 2nd sha"}]

now i want to extract each variable out of this.. after googling for a while i got this

$(document).ready(function(){
    var output = $('#output');

    $.ajax({

        url: 'http://xxxx.com/android_sha/index.php',
        dataType: 'jsonp',
        jsonp: 'jsoncallback',
        timeout: 5000,
        success: function(data, status){
            $.each(data, function(i,item){
                var landmark = '<h1>'+item.sha_id+'</h1>'
                + item.sha_id+'</p>';

                output.append(landmark);
            });
        },
        error: function(){
            output.text('There was an error loading the data.');
                alert("error");         
        }
    });
});

but it always alert error for me. I could be something wrong at $.each(data, function(i,item){ but can’t figure out what should be the correct format.

  • 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-28T00:32:58+00:00Added an answer on May 28, 2026 at 12:32 am

    JSONP isn’t actually JSON. JSONP is a “hack” to get crossdomain data. JSONP is actually JavaScript file.

    You need to wrap the JSON in a function call. In your example, you’re sending the jsoncallback callback, so you need to wrap the JSON in the value of that.

    $callback = $_GET['jsoncallback'];
    while($row = mysql_fetch_assoc($result)){
      $records[] = $row;
    }
    echo $callback . '(' . json_encode($records) . ');';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just created a PHP page that spits outs some data from my database
I have a simple php page which outputs a table (which has been created
I have created a PHP form, which, upon submission, goes to another PHP page.
A jQuery AJAX request .post()s data to page.php, which creates $res and var_dump()s it.
I have created a html page in php and upon submission i validates that
Learning php! I have a sql database which contains a table called 'images' which
Drupal 7 field collection - If I want to theme a node page which
i'm trying to parse a xml string with NSXMLParser which i created in PHP.
I'm working on a site and created this experimental script which populates a category
I've created a PHP web form which when all the data is present has

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.