Welcome Guest, Not a member yet? Register   Sign In
problems with ajax
#1

[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
Code:
"?q=" + username;
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.


Messages In This Thread
problems with ajax - by El Forum - 09-01-2008, 04:59 PM
problems with ajax - by El Forum - 09-01-2008, 05:43 PM
problems with ajax - by El Forum - 09-01-2008, 05:47 PM
problems with ajax - by El Forum - 09-01-2008, 06:20 PM
problems with ajax - by El Forum - 09-01-2008, 07:01 PM
problems with ajax - by El Forum - 09-01-2008, 08:04 PM
problems with ajax - by El Forum - 09-01-2008, 08:18 PM
problems with ajax - by El Forum - 09-01-2008, 08:22 PM
problems with ajax - by El Forum - 09-01-2008, 09:04 PM
problems with ajax - by El Forum - 09-01-2008, 09:18 PM
problems with ajax - by El Forum - 06-14-2010, 06:47 AM



Theme © iAndrew 2016 - Forum software by © MyBB