I want to pass multiple values from from different <div>
tags to another php page( onewaytrip_passenger_data.php
) using ajax code on button onclick()
function. This is my ajax function:
<script language="javascript">
function continoue(){
var a=$("#temp").text();
var b=$("#sno").text();
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("temp").innerHTML=xmlhttp.responseText;
document.getElementById("sno").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","onewaytrip_passenger_data.php?count="+a+"seatno="+b,true);
xmlhttp.send();
}
</script>
#temp
and sno
are my two different <div>
id's these are my <div>
tags
<div id="temp" style="visibility:hidden;"></div>
<div id="sno" style="visibility:hidden;"></div>
This is my button:
<input name="continoue" type="image" src="images/contioue.png" onclick="continoue()"/>
Use jQuery ajax function:
function continoue(){
var a=$("#temp").text();
var b=$("#sno").text();
$.ajax({
type: "GET",
url: "onewaytrip_passenger_data.php",
data : {count:a, seatno:b},
success: function (response) {
if (response == "success" ) {
//do something
} else {
//something
}
},
error: function () {
//console.log('Error --------');
}
});
}
in PHP file after your success code is done,
just write
<?php echo "success"; ?>
for failure,
<?php echo "failure"; ?>
Try this :
<script type="text/javascript">
var a = $("#temp").html();
var b = $("#sno").html();
$.get("onewaytrip_passenger_data.php", {count: a, seatno: b})
.done(function (data) {
alert("Data Loaded: " + data);
}).fail(function () {
alert("error");
});
</script>
Please read this also for your reference.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.