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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:30:53+00:00 2026-05-24T10:30:53+00:00

Been reading up on php and json and am trying this piece of code

  • 0

Been reading up on php and json and am trying this piece of code which is not working and I can’t figure out why. Any help is appreciated.

I call a JavaScript function from my html file onLoad(). That function is

    function getSched()
    {
        $.post("schedlz.php", {dat: ""+inputString+"", action: "searchSched"}, function(data)
    {
            var y="";
    if(data.length >0) 
    {
        var obj = JSON.parse(data);
        y = getRes (data);
        }
        else //some error handler
}
function getRes(data)
{
    var str="";
    var obj = JSON.parse (data);
    alert (data.length + " | " +obj + " | ");
    return str;
}

In schedlz.php file

$conn = getDbConn();
mysql_select_db("myschedulez", $conn);
$result = mysql_query($sql,$conn) or die('Error: ' . mysql_error());
    $rows = array();
    while ($r = mysql_fetch_assoc($result))
    {
        // $rows['schedulez'][] = $r;
        $rows[] = $r;
    }
    echo json_encode($rows);
 mysql_close($conn);

The problem is that I get the data back in correct json format but when I parse it, there is no Object. What could be going wrong here?

  • 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-24T10:30:55+00:00Added an answer on May 24, 2026 at 10:30 am

    You need to add the dataType parameter to your $.post, which in your case is json.
    I’m also not sure if you closed $.post correctly in your sample so I’m adding the closing ); as well.

    function getSched()
    {
        $.post("schedlz.php", 
        {dat: ""+inputString+"", action: "searchSched"}, 
        function(data) {
          var y="";
          if(data.length >0) 
          {
            var obj = JSON.parse(data);
            y = getRes (data);
          }
          else {} //some error handler
        },
        'json'
        ); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Been reading/searching but can't seem to figure out how to do this without having
I've been reading php code all day and what I can't seem to find
I have the below code written in php and have been reading up on
I have been reading some WordPress PHP code on GitHub and I found that
I have been reading up on multiple PHP frameworks, especially the Zend Framework but
I'm quite new to php and have been reading Larry Ullman book to develop
I've been battling PHP's email reading functions for the better part of two days.
Been reading up on MitB attacks and some things worry me about this. From
I've been reading but can't seem to get a form field to be updated
I've been reading the PHP Docs on Type Juggling and Booleans but I still

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.