PHP file named page.php
<?php
$php_variable = $_GET['param1'];
$uv = str_replace("{ZIP Code}", $php_variable,'http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/ZIP/{ZIP Code}/JSON');
$homepage = file_get_contents($uv);
echo $homepage;
?>
homepage stores the json object that contains three fields I would like to print out those three fields in my html file. I have created a ajax function to print out the fields on the web page.
<form action="../getuv.php">
<select name="param1" onchange="this.form.submit()">
<option value="">Choose a zipcode </option>
<option value="92507">92507</option>
<option value="30078">30078</option>
<option value="92606">92606</option>
<option value="30004">30004</option>
<option value="32034">32034</option>
<option value="37160">37160</option>
</select>
</form>
<script>
$.ajax({
type: "POST",
url: "page.php",
success: function (data) {
console.log(data);
var obj = jQuery.parseJSON( data );
document.getElementById("demo").innerHTML = "UV INDEX" + "<br>" + "Zip code: " + obj[0].ZIP_CODE + "<br>";
}
});
</script>
Nothing gets printed out. Also, at the moment, I got to the php page and stay there. I would like to return back to my original html page.
I do send param1. Param1 is a zip code value that the user chooses from a drop down menu.
echo $homepage;useecho json_encode($homepage);. The format will be JSON andjQuery.parseJSON( data )will no longer be required.