Link to home
Start Free TrialLog in
Avatar of mavmanau
mavmanauFlag for Australia

asked on

Displaying JSON responses on a page.

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!!
Avatar of Gary
Gary
Flag of Ireland image

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.
Avatar of mavmanau

ASKER

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

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?
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
perfect.  Thank you, that solution worked brilliantly.

apologies for time taken to answer.