0

I am have this wired problem, every time the "onreadystatechange" called its not returning anything. for example I remove the if and I tell it to return yes that the state of the ajax change its still not returning instead I will get undefined any Idea why this is happening ?

    function load_page(php_handler, url ,searchString) {


        // Get the ajax object using our function above.
        window.ajax = makeAJAXObject();

        // Tell the AJAX object what to do when it's loaded the page
        window.ajax.onreadystatechange = function () {
            if (window.ajax.readyState == 4) { // 4 means it's loaded ok.
                // For simplicity, I'll just return this

                     return ("yes");
            }
        }

        // Set up the variables you want to sent to your PHP page (namely, the URL of the page to load)
        var queryString = "?url=" + url;
        // Load the PHP script that opens the page
        window.ajax.open("GET", php_handler + queryString, true);
        window.ajax.send(null);


        }

here is my makeAJAXObject function

function makeAJAXObject() { // seems to be working ok 
        var ajaxRequest;  // The variable that makes Ajax possible!

        try {
            // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e) {
            // Internet Explorer Browsers
            try {
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {
                    // Something went wrong
                    return false;
                }
            }
        }
        return ajaxRequest;
    }

I also tried to copy a working version of the script from example I found here and the same thing happens, I am working on the split form that coming with the studio.

Please help !

4

1 回答 1

1

Returning a value from your state change handler will have no effect. When the browser invokes your function, it will pay no attention to anything that's returned.

Change that to an alert or console.log or something to prove to yourself that it works.

于 2013-05-31T17:39:43.990 回答