Nelak Posted January 7, 2007 Share Posted January 7, 2007 Hi,Im using ajax as an auto complete for a PM system for my site (www.eve-resource.net) but im having some problems with IE, works perfectally in firefox. Heres the script:[code]<script language="javascript"> function createRequestObject() { if (window.XMLHttpRequest) { // Mozilla, Safari, Opera... var xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { // IE try { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!xmlhttp) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } return xmlhttp; } // Make the XMLHttpRequest object var http = createRequestObject(); function sendRequest(q) { // Open PHP script for requests http.open('get', '/suggest.php?q='+q); http.onreadystatechange = handleResponse; http.send(null); } function handleResponse() { if(http.readyState == 4 && http.status == 200){ // Text returned FROM the PHP script var response = http.responseText; if(response) { // UPDATE ajaxTest content document.getElementById("searchResults").style.display = "visible"; document.getElementById("searchResults").innerHTML = response; } } } function setvalue(userid, uname){ obj = document.getElementById("searchResults"); obj.style.visibility = "hidden"; obj.style.display = "none"; document.getElementById("q").value = uname; document.getElementById("to").value = userid; } function refresh(){ window.location.reload( false ); }</script>[/code]In firefox uname is put into the visible text box and userid is put into the hidden field, but in IE userid is put into the visible text box and nothing is entered into the hidden field. If someone could help me with this i would be very grateful.Thanks,Chris Quote Link to comment Share on other sites More sharing options...
tomfmason Posted January 7, 2007 Share Posted January 7, 2007 For a full answer to what your problem is please enclose any errors from the javascipt/error console in FF or any that you may get IEOk first thing that I see is that you are setting the size and height to 0px.. This is not needed. You can simply set the obj.style.display to none. This means that it will not take any space on the page until you set the display to block.. Now as far as the createRequestObject function I think that you should consider using this one.. I have tested it in Safri, FireFox, Netscape, Opera, IE6 and IE7. [code]//createRequestObject function thanks to oberfunction createRequestObject() { if (window.XMLHttpRequest) { // Mozilla, Safari, Opera... var xmlhttp = new XMLHttpRequest(); if (xmlhttp.overrideMimeType) xmlhttp.overrideMimeType('text/xml'); } else if (window.ActiveXObject) { // IE try { var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!xmlhttp) { alert('Giving up :( Cannot create an XMLHTTP instance'); return false; } return xmlhttp;}[/code]Also, you may want to consider a more descriptive subject for future posts.Tom Quote Link to comment Share on other sites More sharing options...
Nelak Posted January 7, 2007 Author Share Posted January 7, 2007 [quote author=tomfmason link=topic=121365.msg499140#msg499140 date=1168204620]For a full answer to what your problem is please enclose any errors from the javascipt/error console in FF or any that you may get IE[/quote]How do i get to this? sorry being so unspecific, im new to ajax so therefor dont know what im loking for in terms of errors.Thanks a lot for your help, i really appreciate it,Chris Quote Link to comment Share on other sites More sharing options...
Nelak Posted January 7, 2007 Author Share Posted January 7, 2007 ok i have enclosed all my cod enow (with your create object script :) thanks!)i found the firefox console but cudent find the IE 1, but heres some error i got:Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://www.nelak.net/user/pm.php?a=new :: handleResponse :: line 40" data: no]Source File: http://www.nelak.net/user/pm.php?a=newLine: 40Error: uncaught exception: [Exception... "Component returned failure code: 0xc1f30001 (NS_ERROR_NOT_INITIALIZED) [nsIXMLHttpRequest.send]" nsresult: "0xc1f30001 (NS_ERROR_NOT_INITIALIZED)" location: "JS frame :: http://www.nelak.net/user/pm.php?a=new :: sendRequest :: line 34" data: no]Error: not well-formedSource File: http://www.nelak.net/suggest.php?q=NeLine: 8, Column: 35Source Code:// add a zero in front of numbers<10----------------------------------^Warning: Error in parsing value for property 'display'. Declaration dropped.Source File: http://www.nelak.net/user/pm.php?a=newLine: 0this worries me a lot as its a fair few errors :-/thanks again,Chris Quote Link to comment Share on other sites More sharing options...
Nelak Posted January 13, 2007 Author Share Posted January 13, 2007 can ne1 see an error in my code? :'( 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.