tags:

views:

18

answers:

2

hi i m calling ajax function with htaccess url rewriting.But i m not able to fetch value from server.My code is following..

function lookup(val1,val2) {

        //some code here ////

       if (xmlhttp.readyState==4){
              alert(xmlhttp.responseText); // but i m not getting values
       } 

var str=inputString+'/'+cityid;
xmlhttp.open("GET","http://www.mydomain.in/f/fetchname/"+str,true);
xmlhttp.send();
}

//// htaccess code //

RewriteRule ^f/fetchname/(.*)/(.*)$ fetchname.php?fetchkey=$1&cityidval=$2 [NC]

When i m executing directly from url this is printing value.So there is no error in php page.

Is there any different way to fetch value in htaccess in ajax ?

A: 

Is there any different way to fetch value in htaccess in ajax ?

No. A request is a request, no matter whether it's made through Ajax or on the web browser. Note however that Ajax requests work on the same domain and protocol only! The calling page must also be on http://domain.in in your case.

The only exception comes to mind is a 302 redirect (instead of an internal one). That might give an Ajax request trouble. But your redirection is clearly an internal one, so I don't think that can be it.

Check the URL that gets queried in the Ajax call: Where do inputString and cityid come from? Are you 100% sure they are set? What happens if you output the javascript generated URL and try that in your browser?

Pekka
http://www.mydomain.in/f/fetchname/dwa/17Yes i m getting values when i m running these from url.
Ajay_kumar
@Ajay and the page you are doing the request from is also on `mydomain.in`?
Pekka
$Search=mysql_real_escape_string($_REQUEST['fetchkey']); $cityidloc=$_REQUEST['cityidval'];and i m getting perfetct values from these request.Because when i m ruuning this query (http://www.mydomain.in/f/fetchname/dwa/17)i m getting $Search='dwa' and cityidloc ='17' and my query is executing well.I m echoing values there and trying to fetch text output from ajax server by alert(xmlhttp.responseText);This is echoing on browser well when i m directly executing but through ajax i m not able to fetch values.Is there any problem with my htaccess ?
Ajay_kumar
@ajay is the page you are making the request from on the same domain `mydomain.in`?
Pekka
A: 

I'm not used to working with JS so much, but somehow I do not understand how the code could work... should it not be more along this lines:

xmlhttp.open("GET","somepage.xml",true);
xmlhttp.onreadystatechange = checkData;
xmlhttp.send();

if (xmlhttp.readyState==4){
          alert(xmlhttp.responseText);
} 

(I wanted to post it as a comment, but I can figure out how to get the code correct there)

Killer_X
hereu are fetching values from xml file but i m fetching values from database directly and echoing those values on page.So ajax will intrpret those echos values in xml format and this will be access by xmlhttp.responseText.I think ajax is not understanding returning url due to url rewrite mi right ?
Ajay_kumar
The url is irrelevant. What I wanted to point out here is that you 1st read the response and then do the AJAX call. In my logic this cant work. It might work if you call the function 2x
Killer_X