ajax using jquery and javascript
<input type="text zip" class="form-control error" name="zip" id="zip_text" onchange="return searchdata(this.value);">
<div id="searchdiv"></div>
<script>
function getXMLHTTP() { //function to return the xml http object
var xmlhttp = false;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
xmlhttp = false;
}
}
}
return xmlhttp;
}
function searchdata(search_id) {
alert(search_id);
var strURL = "<?php echo site_url();?>/test?search_id=" + search_id;
//alert (strURL);
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('searchdiv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
IN AJAX file: call $zipcode = $_GET['search_id'];
With jquery: --
<button type="button" class="ghost_ab" id="ghost_ab" data-id="160022">hello test</button>
<script>
jQuery(document).ready(function($) {
$("#ghost_ab").on("click", function(e) {
alert('sdfsdfsf');
e.preventDefault();
var id = $(this).data("id");
alert("ID=" + id);
console.log(id);
$.ajax({
type: "post",
url: "<?php echo site_url();?>/test/",
data: {
id: id
},
cache: false,
success: function(html) {
$('#mdssg').html(html);
}
});
});
});
</script>
IN AJAX file: call $zipcode = $_GET['id'];
<div id="searchdiv"></div>
<script>
function getXMLHTTP() { //function to return the xml http object
var xmlhttp = false;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
xmlhttp = false;
}
}
}
return xmlhttp;
}
function searchdata(search_id) {
alert(search_id);
var strURL = "<?php echo site_url();?>/test?search_id=" + search_id;
//alert (strURL);
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('searchdiv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
IN AJAX file: call $zipcode = $_GET['search_id'];
With jquery: --
<button type="button" class="ghost_ab" id="ghost_ab" data-id="160022">hello test</button>
<script>
jQuery(document).ready(function($) {
$("#ghost_ab").on("click", function(e) {
alert('sdfsdfsf');
e.preventDefault();
var id = $(this).data("id");
alert("ID=" + id);
console.log(id);
$.ajax({
type: "post",
url: "<?php echo site_url();?>/test/",
data: {
id: id
},
cache: false,
success: function(html) {
$('#mdssg').html(html);
}
});
});
});
</script>
IN AJAX file: call $zipcode = $_GET['id'];
Comments
Post a Comment