Jump to content

[SOLVED] Ajax problem


Stooney

Recommended Posts

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'];

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.