Stooney Posted October 10, 2008 Share Posted October 10, 2008 So I am having an issue with using my ajax function to call a page starting with http://. I'm not sure how it all works, but here's what I'm working with. My site uses mod_rewrite. It used to work fine when called the file like ajaxReq('../ajax/test.php') but it seems as if http:// broke it. And due to how the mod_rewrite works I can't call the file directly. I am using an mvc setup, so where you will see http://site.com/ajax/request/test it's designed like http://site.com/controller/action/ajax_filename. My ajax controller takes the name and includes the proper file which produces the output for the ajax request like 'test|testvar'. I am receiving this javascript error: Cannot set property 'innerHTML' of null Will an http:// url not work here? Or am I just missing something? Also, any comments on the design of how it works? I'm not by any means ajax savvy. index.php <div id="test"></div><input type="button" value="click" onClick="ajaxReq('http://site.com/ajax/request/test?var=testvar')"> ajax.js function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function ajaxReq(action) { http.open('get', action); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; var update = new Array(); if(response.indexOf('|' != -1)) { update = response.split('|'); document.getElementById(update[0]).innerHTML = update[1]; } } } test.php echo 'test|'.$_GET['testvar']; Quote Link to comment Share on other sites More sharing options...
corbin Posted October 10, 2008 Share Posted October 10, 2008 AJAX and remote URLs == no go. Full URI won't work. Quote Link to comment Share on other sites More sharing options...
Stooney Posted October 10, 2008 Author Share Posted October 10, 2008 Ty for clearing that up corbin. I solved the problem by sending the non mod rewritten url straight to the router. So instead of http://site.com/ajax/request/test?var=testvar I used index.php?d=ajax/request/test?var=textvar Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.