TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Javascript, AJAX, E4X (http://www.talkphp.com/javascript-ajax-e4x/)
-   -   Sending and Retrieving Data (http://www.talkphp.com/javascript-ajax-e4x/1628-sending-retrieving-data.html)

WinSrev 12-05-2007 04:49 PM

Sending and Retrieving Data
 
Hey,

Been having a bit of a problem with my Ajax script, i have this for the link:

Code:

<a href="#" onClick="getData('revision.php?mid=3&sesion=2&user=1', 'messageContent');">
and this for the ajax side of it:

Code:

var XMLHttpRequestObject = false;

try {
        XMLHttpRequestObject = new ActiveXObject("MSXML2.XMLHTTP");
} catch(exception1) {
        try {
                XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(exception2) {
                XMLHttpRequestObject = false;
        }
}

if (!XMLHttpRequestObject && window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest();
}

function getData(dataSource, divID)
{
        if(XMLHttpRequestObject) {
                var obj = document.getElementById(divID);
                XMLHttpRequestObject.open("GET", dataSource);
               
                XMLHttpRequestObject.onreadystatechange = function()
                {
                        if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
                                obj.innerHTML = XMLHttpRequestObject.responseText;
                        }
                }
               
                XMLHttpRequestObject.send(null);
        }
}

but nothing seems to happen? any ideas? Thanks :-)

Rendair 12-05-2007 05:20 PM

When ever i use ajax i use the following code.

PHP Code:

<script language="javascript" type="text/javascript">
<!-- 
function 
ajaxFunction(){

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
                
alert("Your browser broke!");
                return 
false;
            }
        }
    }
    
// Create a function that will receive data sent from the server
    
ajaxRequest.onreadystatechange = function(){
        if(
ajaxRequest.readyState == 4){
          
document.getElementById("id").innerHTML ajaxRequest.responseText;
        }
    }
    
ajaxRequest.open("GET""process.php?id=1&id2=2"true);
    
ajaxRequest.send(null); 
}
//-->
</script> 


Wildhoney 12-05-2007 05:22 PM

1 Attachment(s)
That works perfectly for me in Internet Explorer 7 and Mozilla Firefox 2.0.0.11 (Anyone else noticing Mozilla release lots of updates recently?).

See the attached file, try just running that on its lonesome and seeing what happens.

WinSrev 12-05-2007 05:34 PM

Well, it's half working although here mid=3&sesion=2&user=1 for some reason it's going to the PHP script through the Ajax as mid=1&sesion=1&user=1

Any ideas?

WinSrev 12-05-2007 06:35 PM

Nevermind! All fixed now ! :-)

Thanks for all the help!

Wildhoney 12-05-2007 07:32 PM

Care to share how you fixed it? Just in case anybody else is having a similar issue.

WinSrev 12-05-2007 07:57 PM

It was actually a PHP issue, so, that Ajax code and HTML works.

CMellor 12-06-2007 01:50 AM

Pssst... use Prototype

Yeah Wildhoney, I've noticed all the Firefox updates lately...wutupwidat!? Though I'm still on .06 because of Vista, it won't let me update it for some strange buggered up reason.

Wildhoney 12-06-2007 02:19 AM

Well I think Firefox is still on a slippery at the moment, it in my books anyway. The only reason I use Firefox now is because there's no Firebug available for Opera. Though I believe Opera are in the process of developing one! When comparing the 2, the speed difference these days is astonishing. It shows you how far Firefox has dropped in terms of being a light-weighty and speedy browser.

WinSrev 12-06-2007 01:32 PM

Netscape is pretty awesome, and really quick, even thought it is based around FireFox they have done some work to it.

Wildhoney 12-06-2007 02:40 PM

Well, Netscape is based on the layout engine, not actual Firefox. Just the way it renders the elements. There are quite a few layout engines, for which every developer should have at least one browser with each layout engine to ensure their website works perfectly with it - the most popular ones, anyway:
  • Gecko (Mozilla)
  • GtkHTML (GNOME)
  • iCab (Alexander Clauss)
  • KHTML (KDE)
  • Presto (Opera)
  • Robin (Ritlabs)
  • Tasman (Microsoft)
  • Trident (Microsoft)
  • WebCore (Apple)

wiifanatic 02-18-2008 12:18 AM

I thoght it was called WebKit:
WebKit (Apple)


All times are GMT. The time now is 10:40 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0