Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Ajax i Glupi IE7

[es] :: Javascript i AJAX :: Ajax i Glupi IE7

[ Pregleda: 1484 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

nemnesic
nemnesic
Software Developer
Vranje Florida

Član broj: 44355
Poruke: 802
*.sfcc.edu.



+64 Profil

icon Ajax i Glupi IE715.02.2007. u 15:31 - pre 210 meseci

malopre sam primetio da moj AJAX code ne radi sa IE7.
Mozilla, FF, IE6 rade bez problema. znam da IE7 ima native support for AJAX sada...ali pojma nemam sta da radim...
jel moze neko da mi kaze sta da radim
novajlija sam sto se tice AJAX-a.

svaki comment je dobro dosao! :)

Code:

<script type="text/javascript">
// <![CDATA[

//-----------------------------------------------------------------------------
// Define some constants.
//-----------------------------------------------------------------------------

// Define a list of Microsoft XML HTTP ProgIDs.
var XMLHTTPREQUEST_MS_PROGIDS = new Array(
    "Msxml2.XMLHTTP.7.0",
    "Msxml2.XMLHTTP.6.0",
    "Msxml2.XMLHTTP.5.0",
    "Msxml2.XMLHTTP.4.0",
    "MSXML2.XMLHTTP.3.0",
    "MSXML2.XMLHTTP",
    "Microsoft.XMLHTTP"
);

// Define ready state constants.
var XMLHTTPREQUEST_READY_STATE_UNINITIALIZED = 0;
var XMLHTTPREQUEST_READY_STATE_LOADING       = 1;
var XMLHTTPREQUEST_READY_STATE_LOADED        = 2;
var XMLHTTPREQUEST_READY_STATE_INTERACTIVE   = 3;
var XMLHTTPREQUEST_READY_STATE_COMPLETED     = 4;

//-----------------------------------------------------------------------------
// Returns an XMLHttpRequest object.
//-----------------------------------------------------------------------------
function getXMLHttpRequest()
{
    var httpRequest = null;

    // Create the appropriate HttpRequest object for the browser.
    if (window.XMLHttpRequest != null)
        httpRequest = new window.XMLHttpRequest();
    else if (window.ActiveXObject != null)
    {
        // Must be IE, find the right ActiveXObject.
        var success = false;
        for (var i = 0; i < XMLHTTPREQUEST_MS_PROGIDS.length && !success; i++)
        {
            try
            {
                httpRequest = new ActiveXObject(XMLHTTPREQUEST_MS_PROGIDS[i]);
                success = true;
            }
            catch (ex)
            {}
        }
    }

    // Display an error if we couldn't create one.
    if (httpRequest == null)
        alert("Error in HttpRequest():\n\nCannot create an XMLHttpRequest object.");

    // Return it.
    return httpRequest;
}



//-----------------------------------------------------------------------------
// This code uses an XMLHttpRequest object to look up the high school of the
// county entered by the user. That data is then used to populate the
// corresponding form fields.
//-----------------------------------------------------------------------------


var highSchoolLookup = getXMLHttpRequest();

function initiateHighSchoolLookup(event)
{
    
  // Check for a city and state.
  var county  = document.MForm.COUNTY.value;
  
  // Abort any currently active request.
  //highSchoolLookup.abort();
  
  // Clear the high school drop-down list.
    while (document.MForm.elements["highSchoolList"].options.length > 0)
        document.MForm.elements["highSchoolList"].remove(0);

  // Perform an asynchronous request to get a list of zip codes for
  // that city and state.
  var url = "servlet/HS_by_COUNTY?COUNTY=" + encodeURI(county) + "&HS=03020&arr=1297";
  
  highSchoolLookup.onreadystatechange = highSchoolReadyStateChange;
  highSchoolLookup.open("GET", url, true);
  highSchoolLookup.send(null);
}


function highSchoolReadyStateChange()
{
    var statusText;

    // Check the ready state.
    switch (highSchoolLookup.readyState)
    {
        case XMLHTTPREQUEST_READY_STATE_UNINITIALIZED:
            statusText = "";
            break;

        case XMLHTTPREQUEST_READY_STATE_LOADING:
            statusText = "Initialzing High School lookup...";
            break;

        case XMLHTTPREQUEST_READY_STATE_LOADED:
            statusText = "Sending data...";
            break;

        case XMLHTTPREQUEST_READY_STATE_INTERACTIVE:
            statusText = "Downloading data...";
            break;

        case XMLHTTPREQUEST_READY_STATE_COMPLETED:

            // Assume no matches were found.
            statusText = "No High Schools found."

            
            // Get the XML document returned from the request and fill in the
            // form fields.
            try
            {
                var xmlDoc = highSchoolLookup.responseXML;

                // Copy the county attributes from the root XML node to the appropriate form fields.
                var county  = xmlDoc.documentElement.getAttribute("county");
                
                
                // Get all the high school code tags returned from the request.
                var els = xmlDoc.getElementsByTagName("highSchool");

                // Set the status text.
                statusText = els.length + " High Schools found."

                // Add a dummy option to the high school drop-down list.
                var option = document.createElement("OPTION");
                option.text = "Select one...";
                option.value = "";
                try
                {
                    document.MForm.elements["highSchoolList"].add(option, null);
                }
                catch(ex)
                {
                    // For IE.
                    document.MForm.elements["highSchoolList"].add(option);
                }

                // Add an option to to the drop-down list for each high school returned from the request.
                for (var i = 0; i < els.length; i++)
                {
                    option = document.createElement("OPTION");
                    option.text = option.value = els[i].firstChild.nodeValue;
                    try
                    {
                        document.MForm.elements["highSchoolList"].add(option, null);
                    }
                    catch(ex)
                    {
                        // For IE.
                        document.MForm.elements["highSchoolList"].add(option);
                    }
                }

                // Show the drop down list and set focus on it.
                document.MForm.elements["highSchoolList"].style.visibility = "";
                document.MForm.HS.style.visibility = "hidden";
                document.MForm.elements["highSchoolList"].focus();
            }
            catch (ex)
            {}
            break;

        default:
            statusText = "Unknown error.";
            break;
    }

    // Display the status message.
    setStatusText(statusText);
}
function setStatusText(text)
{
    // Display the status message.
    var el = document.getElementById("statusText");
    if (el.firstChild == null)
        el.appendChild(document.createTextNode(""));
    el.firstChild.nodeValue = text;
}
</script>



 
Odgovor na temu

lmilko
Milko Leporis
Novi Sad

Član broj: 118389
Poruke: 11
*.ns.ac.yu.

Sajt: www.milkoleporis.com


Profil

icon Re: Ajax i Glupi IE721.02.2007. u 10:39 - pre 210 meseci
Na mom sajtu www.milkoleporis.com imam aplikaciju uradjenu sa Ajaxom za odabir tema postova i nisam imao problema sa IE7 a skript koji instancira XMLHttpRequest objekat nisam nista menjao

Code:

function createRequestObject() {
        var RequestObj;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer") {
            RequestObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        else {
            RequestObj = new XMLHttpRequest();
        }
        return RequestObj;
    }

var http = createRequestObject();

+--------------------
|Milko Leporis
|www.milkoleporis.com
+--------------------
 
Odgovor na temu

nemnesic
nemnesic
Software Developer
Vranje Florida

Član broj: 44355
Poruke: 802
*.com
Via: [es] mailing liste



+64 Profil

icon Re: Ajax i Glupi IE723.02.2007. u 20:41 - pre 210 meseci
resio sam problem
zaboravio sam da stavim

Code:

// Abort any currently active request.
   highSchoolLookup.abort();


ajax ne radi u IE7 ako ne "Abort any currently active request"

hah!

poz
 
Odgovor na temu

[es] :: Javascript i AJAX :: Ajax i Glupi IE7

[ Pregleda: 1484 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.