[英]How to pass ajax variable value to controller in codeigniter
Here i want to pass the 'q' value from ajax to controller function in codeigniter. 在这里我想将aq的'q'值传递给codeigniter中的控制器函数。
ajax code:
function getdata(str)
{
if (str == "") {
document.getElementById("yer").innerHTML = "";
return;
} else {
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("bus").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","<?php echo site_url('money_c/taxcalculator1'); ?>?q="+str,true);
xmlhttp.send();
window.location="<?php echo site_url('money_c/taxcalculator'); ?>"
}
}
controller:
function taxcalculator1()
{
$bt=$_GET['q'];
echo $bt;
}
Here i want to pass the 'q' value from ajax to controller function in codeigniter. 在这里我想将aq的'q'值传递给codeigniter中的控制器函数。
As soon as you have started the Ajax request sending with this: 一旦启动Ajax请求,就发送以下信息:
xmlhttp.send();
You leave the page with this: 您使用以下方法离开页面 :
window.location="<?php echo site_url('money_c/taxcalculator'); ?>"
… which aborts the Ajax request, removes the place you are trying to edit with innerHTML
and destroys the JavaScript that would be trying to do that anyway. …会中止Ajax请求,删除您要使用
innerHTML
编辑的位置,并破坏无论如何都将尝试执行此操作的JavaScript。
If you want to use Ajax then: 如果要使用Ajax,则:
taxcalculator1
taxcalculator1
的响应中 onreadystatechange
to show it to the user onreadystatechange
将其显示给用户 window.location
line). window.location
行)。 If you want to load an entirely new page: 如果要加载一个全新的页面:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.