Solved

Displaying JSON responses on a page.

Posted on 2014-01-12
5
245 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bootstrap Form 16 37
Google Tag Manager - Add Trigger Using Div class 22 50
Generate PDF from MySQL using PHP 3 52
How would I craft a PDO SELECT based on an IF Statement? 8 28
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

679 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