Solved

Displaying JSON responses on a page.

Posted on 2014-01-12
5
234 Views
Last Modified: 2014-05-12
Hi experts,

Thank you as always for taking a look at my question which i am hoping is an easy one.

I have the below web page.

<!DOCTYPE html>
   <head>
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="totalcall.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.10.3/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/jquery-ui-1.10.3/themes/base/jquery-ui.css" />
 
        <script type="text/javascript">
                $(document).ready(function(){
                    $("#term").autocomplete({
                        source:'getautocomplete.php',
                        minLength:3
                    });
                });
        </script>
   </head>
 
   <body>
 
      <form method="post" action="">
             Name : <input type="text" id="term" name="term" />
      </form>
  
   </body>
</html>

Open in new window


Essentially this sends data off to a php page, which submits the data and returns the results. I know the curl is working because i can see the response when I turn on the dev option in firefox.

What I need to know is how can I get the results to display in either an iframe or a small table on the html webpage.  If you need any of the JS files please advise.

many thanks again!!
0
Comment
Question by:mavmanau
  • 3
  • 2
5 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39775508
You can use appendTo
http://api.jqueryui.com/autocomplete/#option-appendTo
        <script type="text/javascript">
                $(document).ready(function(){
                    $("#term").autocomplete({
                        source:'getautocomplete.php',
                        minLength:3,
                        appendTo: "#id-of-div"
                    });
                });
        </script>

Open in new window

The proviso of this is the div you want to show the results in must be in the same container as your input field.
0
 

Author Comment

by:mavmanau
ID: 39775546
Hi,

I tried this, but nothing is still coming through.

<!DOCTYPE html>
   <head>
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="totalcheck.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.10.3/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/jquery-ui-1.10.3/themes/base/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="totalcheck.css" />
 
        <script type="text/javascript">
                $(document).ready(function(){
                    $("#term").autocomplete({
                        source:'getautocomplete.php',
                        minLength:3,
						appendTo: "#resultsname"
                    });
                });
        </script>
   </head>
 
   <body>
 
      <form method="post" action="">
             <p>Name :
  <input type="text" id="term" name="term" />
             </p>
             <div name="resultsname" id="resultsname"></div>
             <p>&nbsp;</p>
      </form>
  
   </body>
</html>

Open in new window

0
 

Author Comment

by:mavmanau
ID: 39775560
I have it now displaying "No results found then the text box - which is strange because i can see the data that is being generated from the PHP file.  

Do I need to show you my PHP file perhaps?  or Am i calling it incorrectly?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39775663
Try
<!DOCTYPE html>
   <head>
<script type="text/javascript" src="scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="totalcheck.js"></script>
<script type="text/javascript" src="scripts/jquery-ui-1.10.3/ui/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/jquery-ui-1.10.3/themes/base/jquery-ui.css" />
<link rel="stylesheet" type="text/css" href="totalcheck.css" />
 
        <script type="text/javascript">
                $(document).ready(function(){
                    $("#term").autocomplete({
                        source:'getautocomplete.php',
                        minLength:3,
						appendTo: "#resultsname"
                    });
                });
        </script>
   </head>
 
   <body>
 
      <form method="post" action="">
             <p>Name :
  <input type="text" id="term" name="term" />

             <div name="resultsname" id="resultsname"></div>
             </p>
      </form>
  
   </body>
</html>

Open in new window

0
 

Author Closing Comment

by:mavmanau
ID: 40060841
perfect.  Thank you, that solution worked brilliantly.

apologies for time taken to answer.
0

Featured Post

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now