Question: I am using the chosen jquery plugin which turns a multi slect box into a facebook style selector. I am filling it with UK postcodes as well as displaying selected postcodes as well.

As my PHP request is retrieving a lot of data from my postcode database the page obviously runs quite slow, but I want to be able to only retrieve data once the user has entered 1 character in the input box.

I know I will have to do it with Ajax and I think JSON, but now sure how?

Here is my code

```
    <select name="zipcode[]" style="width:600px; height:250px;" multiple class="chzn-select" id="zipcode">

          <?php $arraypostcode = explode(",", $zipcode); ?>
    <?php
do { // begin loop
?>
    <option value="<?php echo $row_postcode['code']?>"<?php for ($i=0; $i<sizeof($arraypostcode); $i++) {if ($row_postcode['code'] == $arraypostcode[$i]) {echo " selected"; break;}}?>><?php echo $row_postcode['code']?></option>
    <?php
} while ($row_postcode = mysql_fetch_assoc($postcode)); // end loop
  $rows = mysql_num_rows($postcode);
  if($rows > 0) {
      mysql_data_seek($postcode, 0);
      $row_postcode = mysql_fetch_assoc($postcode);
  }
?>
  </select>

```

PHP request:

```
<?php

$postcode = mysql_query( "SELECT postcode.code FROM postcode");
$row_postcode = mysql_fetch_assoc($postcode);
$totalRows_postcode = mysql_num_rows($postcode);

?>

```

Any Ideas?

Answer: 
What you're looking for is a scriptable/headless browser. In decreasing order of popularity, the options are:

* [Google Puppeteer](https://github.com/GoogleChrome/puppeteer) - "Node library which provides a high-level API to control Chrome or Chromium"
* [Zombie](https://github.com/assaf/zombie) - more lightweight; "Insanely fast, headless full-stack testing using Node.js"
* [slimerjs](https://github.com/laurentj/slimerjs) - scriptable Firefox. No commits since March 2018.
* [mechanize-js](https://github.com/srveit/mechanize-js/issues/4), which lacks documentation and has far less traction than any of the above alternatives

Abandoned projects
------------------

* [PhantomJS](https://github.com/ariya/phantomjs) - headless WebKit.
* [chimera](https://github.com/deanmao/node-chimera) - abandoned since 2013
The closest tool I have found for now is [zombie](https://github.com/assaf/zombie).

Apparently it is not exactly ready for production (and may never be) as it is a testing tool.
Nevertheless it seems that it is the closest match for the functionality needed (and it supports JS!)