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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:53:07+00:00 2026-05-13T18:53:07+00:00

I have a problem with the jquery $.get function. I’m trying to get data

  • 0

I have a problem with the jquery $.get function.
I’m trying to get data from PHP file needed to check does the specific user has subscription and is he recorded at ignore list by other users.

With this jquery code I can get only one of this two data from MySql using PHP file.

The jquery code is:

$(document).ready(function(){
    $.get("getdata.php", function(returned_data) { 
        if(returned_data === "1") {
            $("div#wall").html('user has no subscription');
            $("#message_wall").attr("disabled", "disabled");
            return false;
        }
    });
});

The PHP file has MySQL query and that page looks like this:

$query = mysql_query("SELECT * FROM subscription WHERE id=$ipr");
$result = mysql_fetch_assoc($query);

if (time() > $result['date']) {
    echo "1";
} else {
    echo "5";
}


$res = mysql_query("SELECT * FROM ignor WHERE migid=$ipr AND igid=$id") or die(mysql_error());
$num_rows = mysql_num_rows($res);
if ($num_rows >= "1") {
    echo "2";
}

The thing that I need from jquery $.get function is separeted .attr() and .html() for each PHP echo response code (for echo “1”, echo “2” and echo “5”)

How can I do that with Jquery $.get?

  • 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-13T18:53:07+00:00Added an answer on May 13, 2026 at 6:53 pm

    Like Jake said, using $.getJSON is better. jQuery has built in support for receiving JSON as a response from the web server, so we don’t need any additional JSON libraries on the javascript side for such a simple task. Also on the PHP side, we can build up the JSON response (to be sent to the javascript) using hand-rolled JSON for this simple scenario.

    The PHP code would look something like this:

    $query = mysql_query("SELECT * FROM subscription WHERE id=$ipr");
    $result = mysql_fetch_assoc($query);
    
    if (time() > $result['date']) {
        echo '{ "resultCode":1, "description":"message 1 to be displayed to user" }';
    } else {
        echo '{ "resultCode":5, "description":"message 5 to be displayed to user" }';
    }
    
    $res = mysql_query("SELECT * FROM ignor WHERE migid=$ipr AND igid=$id") or die(mysql_error());
    $num_rows = mysql_num_rows($res);
    if ($num_rows >= "1") {
        echo '{ "resultCode":2, "description":"message 2 to be displayed to user" }';
    }
    

    The javascript can then be updated to the following:

    $(document).ready(function(){
        $.getJSON("getdata.php", function(returned_data) { 
    
            // returned_data is now a javascript object with 2 properties:
            //   returned_data.resultCode
            //   returned_date.message
    
            // if the user has a valid subscription
            if (returned_data.statusCode === 5) {
                $("#message_wall").removeAttr("disabled");
                return true;
            }
            // if the user has an invalid subscription, show the message returned from the PHP
            else {
                $("div#wall").html(returned_data.message);
                $("#message_wall").attr("disabled", "disabled");
                return false;                
            }
        });
    });
    

    Also if you need to be able to send multiple responses back to the javascript, you can build up the JSON response objects into a javascript array so that the response from the PHP code looks like this:

    [ { "resultCode":1, "description":"msg" }, { "resultCode":2, "description":"msg" }, ... ]
    

    your javacript will then receive an array in the returned_data parameter, which can be iterated by using the built-in $.each() function.

    For more info on JSON, see json.org

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.