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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:45:21+00:00 2026-05-17T19:45:21+00:00

I have a php file that receives data from mySQL table. The mySQL table

  • 0

I have a php file that receives data from mySQL table. The mySQL table ‘user_spec’ has only one field ‘options’ that it returns. Then I convert returned data into JSON, under is code doing that.

<?php 
 $username = "user"; 
 $password = "********"; 
 $hostname = "localhost"; 
 $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect  
         to MySQL"); //print "Connected to MySQL<br>"; 
 $selected = mysql_select_db("spec",$dbh) or die("Could not select first_test"); 
 $query = "SELECT * FROM user_spec"; 
 $result=mysql_query($query);  
 echo json_encode(mysql_fetch_assoc($result)); 
?> 

then in an HTML file, I try to output data by this piece of code But it is not working. I will be very thankful for any help.

<html>
    <head>
    <script type="text/javascript"   
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" language="javascript">
    function Preload() {
    $.getJSON("Dhttp://localhost/conn_mysql.php", function(json){
    alert("JSON Data: " + json.user_spec);
    });}

    </script></head>
    <body onLoad="Preload()">
    </body>
    </html> 
  • 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-17T19:45:21+00:00Added an answer on May 17, 2026 at 7:45 pm

    I think instead of using the file adress: “D:xampp/htdocs/conn_mysql.php” you must use an url defined by xampp such as “http://localhost/mytest/conn_mysql.php”

    Another thing you need to look out is the method. $.getJSON (http://api.jquery.com/jQuery.getJSON/), as its name says, works with the GET method. Maybe you should try $.post or $.ajax (http://api.jquery.com/jQuery.post/).

    Oh! And to start your script, not all the browsers supports the <body onload=””>. Furthermore, it waits for the page to be loaded, not the DOM, what can give you problems with your scripts sometimes.
    You should use $(‘document’).ready(function(), that waits for the DOM to be loaded.
    This way:

    <script type="text/javascript">
    $('document').ready(function()
    {
    
        $.getJSON("D:xampp/htdocs/conn_mysql.php", function(json){
        alert("JSON Data: " + json.options);
    
    });
    </script>
    

    I hope it can be useful! ^^

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

Sidebar

Related Questions

Alright, currently I have my SWF hitting a php file that will go and
I have a PHP script that processes file uploads. The script tries to organise
I have an htaccess file that uses mod_rewrite to redirect /controller to /index.php?controller=%controller% Like
I have a PHP client that requests an XML file over HTTP (i.e. loads
I have a PHP script that pushes the headers to allow a file to
I have some jQuery code. I have called an Ajax function file, file.php, that
I have a PHP file, Test.php, and it has two functions: <?php echo displayInfo();
I have a script that appends some rows to a table. One of the
i have a php file launching my exe. the exe does cout and the
I have a php file which I will be using as exclusively as an

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.