Forum Moderators: open
function available(response)
{
var divresponse = document.getElementById('response');
if (response == "Success!") {
window.location='https://www.mysite.com/page.php';
}
}
else{
?>
<div id="response">
<p>Success!</p>
</div>
<?php
}
It is not clear if response is
Success!
or
<p>Success!</p>
or maybe
<div id="response">
<p>Success!</p>
</div>
function available(response)
{
alert(response);
var divresponse = document.getElementById('response');
if (response == "Success!") {
window.location='https://www.mysite.com/page.php';
}
}
<div id="response">
<p>Success!</p>
</div>
Your test is
if (response == "Success!") {
I assume response is the PHP generated reply resulting from ajax request. For test to work red text needs to exactly match full PHP reply.
Did not work, nothing happened at all.
Do you have early version that works to any extent ?
if (!empty($percentage) && !empty($terms)) {
if ($salida > $llegada){
$query = $dbh->prepare("SELECT DATE_FORMAT(llegada, '%e %b %Y') as lleg, DATE_FORMAT(salida, '%e %b %Y') as sal,tiporeserva, propiedad, TO_DAYS(:salida) - TO_DAYS(:llegada) as dias from bookings where ( propiedad = :propiedad )
AND ((:llegada2 BETWEEN llegada AND date_sub(salida, interval +1 day))
or (:salida2 BETWEEN date_sub(llegada, interval -1 day) AND salida) or (llegada <= :llegada3 AND salida >= :salida3) or (llegada >= :llegada4 AND salida <= :salida4))");
$query->execute(array(
'salida' => $salida
, 'llegada' => $llegada
, 'propiedad' => $propiedad
, 'llegada2' => $llegada
, 'salida2' => $salida
, 'llegada3' => $llegada
, 'salida3' => $salida
, 'llegada4' => $llegada
, 'salida4' => $salida
));
$query->setFetchMode(PDO::FETCH_OBJ);
if ($row = $query->fetch()) {
if ($row->tiporeserva=="larga"){ echo "<p>This property is available only for long term rentals, consult us for a price.</p>
"; }
else {
$propiedad = str_replace("_", " ", $propiedad);
echo "<p>$propiedad is not available from $arrival_display to $departure_display.</p>";
echo "<p>$propiedad is occupied from ". $row->lleg ." until ". $row->sal ."</p>";
}
}//end if available query fetch
else{
?>
REDIRECTION SHOULD COME HERE
<?php
}//end else if available
}//end if salida mayor
else {echo "<span class=\"red\"><p>There is an error with the dates please try again, arrival: $arrival_display and departure: $departure_display</p> </span>";}
}//end if !empty form
else { echo "<p>Please fill in bookingoptions choosen (25% or 50%) and accept booking terms and conditions to proceed with the booking.</p>"; }
}
?>
function objetoAjax(){
var xmlhttp=false;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
function dataChanged() {
document.getElementById("resultado").style.display = "none";
}
function enviarDatosSolicitud(){
var divResultado = document.getElementById('resultado');
divResultado.style.display = "block";
propiedad = document.solicitud.propiedad.value;
terms = document.solicitud.propiedad.value;
percentage = document.solicitud.propiedad.value;
day = document.solicitud.day.options[document.solicitud.day.selectedIndex].value;
day2 = document.solicitud.day2.options[document.solicitud.day2.selectedIndex].value;
month = document.solicitud.month.options[document.solicitud.month.selectedIndex].value;
month2 = document.solicitud.month2.options[document.solicitud.month2.selectedIndex].value;
ajax=objetoAjax();
ajax.open("POST", "calculator.php",true);
ajax.onreadystatechange=function() {
if (ajax.readyState==4) {
divResultado.innerHTML = ajax.responseText
LimpiarCampos();
}
}
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send("propiedad="+propiedad+"&enviar="+enviar+"&day="+day+"&day2="+day2+"&month="+month+"&month2="+month2+"&percentage="+percentage+"&terms="+terms+"")
}
function dataChanged() {
document.getElementById("resultado").style.display = "none";
}
function enviarDatosSolicitud(){
var divResultado = document.getElementById('resultado');
divResultado.style.display = "block";
if (divResultado.length == 0)
{
window.location.href = '/myotherpage.php'
}
if( $('#resultado').is(':empty') )
{
window.location.href = '/myotherpage.php'
}
if( $('#resultado:empty').length )
{
window.location.href = '/myotherpage.php'
}
function dataChanged() {
document.getElementById("resultado").style.display = "none";
}
function available()
{
document.getElementById('resultado');
if (resultado == "available") {
window.location='https://www.mysite.com/page.php';
}
}
function enviarDatosSolicitud(){
var divResultado = document.getElementById('resultado');
divResultado.style.display = "block";
else{
echo "available";
}