views:

104

answers:

3

Hello,

Long time reader, first time poster. Any help is greatly appreciated.

I have crafted an AJAX query using JavaScript. The script works correctly, and the interface does what I want, but Firefox is giving me an error message related to the PHP file being hit. It's strange, because it seems to suggest there's a syntax error in the PHP, but that doesn't make any sense. This is the error:

Error: syntax error Source File: http://www.mysite.com/includes/ajax.php?action=checkpsudo&value=fd Line: 1, Column: 1 Source Code: yes

And the Javascript is below. Can anybody help me out? Thanks.

var ajaxobject = createajaxobjectObject();

function createajaxobjectObject() {
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        ajaxobject = new XMLHttpRequest();
        if (ajaxobject.overrideMimeType) {
            // set type accordingly to anticipated content type
            ajaxobject.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            ajaxobject = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxobject = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!ajaxobject) {
        alrt('Cannot create XMLHTTP instance');
        return false;
    }
    return ajaxobject; 
}

function checkpsudo(value) {    

    if (value == "") {
        document.getElementById('feedback').innerHTML = "Please select a psudonym";
        document.getElementById('feedback').className = "fail";
        document.getElementById('done').disabled=true;  
    } else {
        ajaxobject.onreadystatechange = function() { check(); };              
        ajaxobject.open('GET', '/includes/ajax.php?action=checkpsudo&value='+value, true);
        ajaxobject.send(null);  
    }


}

function check() {
    if (ajaxobject.readyState == 4) {

        //IF WE GOT OUR CHAT XML BACK CORRECTLY
        if (ajaxobject.status == 200) {             

            var response = ajaxobject.responseText;

            var value = document.getElementById('psudoentry').value;

            if(response=='no') {
                document.getElementById('feedback').innerHTML = "'" + value + "' is already being used";
                document.getElementById('feedback').className = "fail";
                document.getElementById('done').disabled=true;
            } else {
                document.getElementById('feedback').innerHTML = "'" + value + "' is available";
                document.getElementById('feedback').className = "success";
                document.getElementById('done').disabled=false;
            }                                          

        } else {
            alert('There was a problem with the request.');
        }
    }
}
A: 

Why shouldn't that make sense? If the php file has a syntax issue than the ajax call will get back the error page your server spits out and that will show up in the FF error-console while FF tries to parse the response

jitter
I just meant that it didn't make sense that it was detecting syntax errors with the PHP page. But now I understand that the script was looking for XML and not getting it, so it had a problem with the source file. Makes perfect sense now. Thanks!
Mike
Ok. Glad to help. Now please consider upvoting and/or accepting my answer as the correct one (checkmark near my answer)
jitter
+1  A: 

It sorta looks like your PHP may be generating a notice or a warning - then the first thing in the generated XML isn't an XML element, but the string "Notice: etc. etc.", which causes the browser to complain that what it's getting doesn't match the format it expects. In my experience, sometimes this breaks everything and sometimes there isn't any obvious effect. I'd turn off notices and warnings on your server - and if that clears up the problem, then you know where to start tracking it down.

Ryan Mitchell
+1  A: 

My first instinct is that this is not a problem with your JS but with the XML being output by the PHP script.

LeguRi