I need to write a php code using ajax to get a respond from http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius webserver. below is the code which will post request and get the respond. since it is a post request the site get refreshed. without refreshing i need the respond.I dont know how to do it in ajax. please help me. thanks alot.
<?php
if (isset($_POST['Fahrenheit'])&&$_POST['Fahrenheit']!=null) {
$out = print_name($_POST['Fahrenheit']);
}
else {
print_form();
}
function print_name($name) {
$ch = curl_init();
$far = 'Fahrenheit='.$name;
curl_setopt($ch, CURLOPT_URL,"http://www.w3schools.com/webservices/tempconvert.asmx /FahrenheitToCelsius");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$far);
// http_build_query(array('postvar1' => 'value1')));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
echo 'It is: '.$server_output;
return $server_output;
}
function print_form() {
echo '
<form method="post">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td>
<input class="frmInput" type="text" size="30" name="Fahrenheit">
</td>
</tr>
<tr>
<td></td>
<td align="right">
<input name="cel" type="submit" value="Submit" class="button">
</td>
</tr>
</form>
';
}
please help me.