[eluser]dumbo[/eluser]
Hi, I'm new to CI as well as javascripts & AJAX. I have a noobie question about how to pass in a variable from the view's javascript and how to access it in the controller.
View's [removed]
Code:
var httpObj;
function checkName(username)
{
httpObj = GetHttpObject();
if(httpObj == null)
{
alert ("Browser does not support HTTP Request");
return;
}
var url = <?php echo base_url().'index.php/addaccount/username_check';?>;
url=url+"?q=" + username;
url=url+"&sid;="+Math.random();
httpObj.onreadystatechange=callback_account;
httpObj.open("GET",url,true);
httpObj.send(null);
}
function callback_account()
{
if (httpObj.readyState==4 || httpObj.readyState=="complete")
{
alert(httpObj.responseText);
}
}
function GetHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
[removed]
Controller's function:
Code:
function username_check()
{
echo($this->input->get('q'));
}
So my question is can I actually pass in
if I didn't activate query string in my config? If I can't, is there a way around this without using query strings?
My second question is how do I access that variable in controller after it's pass in?
Right now my username_check function returns blank.
Please let me know if there is anything unclear. Thanks.