Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 07-22-2008, 02:26 PM Problem with Ajax
Tulork's Avatar
Experienced Talker

Posts: 38
Location: Sweden
Trades: 0
Why wont this work in any other browser then FireFox? It seems to be a problem with the browser check... but I've tried so many different methods for checking browser... nothing works.

fetch.js
Code:
function xmlhttpPost(strURL) {
    var xmlHttpReq = false;

    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    if (window.ActiveXObject) {
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xmlHttpReq.open('POST', strURL, true);
    xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xmlHttpReq.onreadystatechange = function() {
    
         
         if (xmlHttpReq.readyState == 1) {
            updatepage('<br /><br /><img src="loader.gif" border="0" alt="" style="margin-left:15px;" />');
        }

        
        if (xmlHttpReq.readyState == 4) {
            updatepage(xmlHttpReq.responseText);
        }
    }
    xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    var form     = document.forms['feeds'];
    var word = form.feed.value;
    qstr = 'feed=' + escape(word);
    return qstr;
}

function updatepage(str){
    document.getElementById("result").innerHTML = str;
}
index.html
HTML Code:
<html>
<head>
<script type="text/javascript" src="js/fetch.js"></script>
</head>
<body>
<form name="feeds" action="index.html" method="POST">
  <select name="feed">  
  <option value="">Välj</option>
  <option value="http://www.geiser.se/feed" onclick='xmlhttpPost("show_feed.php")'>Geiser.se</option>
  <option value="http://feeds.feedburner.com/tkjblogg?format=xml" onclick='xmlhttpPost("show_feed.php")'>TkJ</option>
  <option value="http://www.dan.se/feed" onclick='xmlhttpPost("show_feed.php")'>Dan.se</option>
  </select><br />
  <div id="result"></div>
</form>
</body>
</html>
show_feed.php
PHP Code:
<?php
$url 
$_POST['feed'];
    if(isset(
$_POST['feed']))
    {
        if(
preg_match("/http:/"$url))
        {
            require_once(
"class_rss.php");        //Hämtar klassen
            
$rss = new rssHandler();            //Skapar instans till klassen

                //Här anger du RSS-feedens url
            
$antal 20;                        //Här anger du hur många inlägg du vill skriva ut
            
            //Här skickar du in datan som klassen behöver och skriver ut den
            
echo $rss->show_feed($url$antal);
        }
    }
?>
I have tried without any checks in PHP... that isn't it. Everything works as it should in FF, but not in IE or Safari...
__________________
Hurray for me (not)
Tulork is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-22-2008, 08:04 PM Re: Problem with Ajax
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
use the try ... catch exception method, it's more reliable

http://www.w3schools.com/ajax/ajax_browsers.asp
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is offline
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-23-2008, 01:08 AM Re: Problem with Ajax
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
I use this...

Code:
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = false;
      }
    }
  }

  if (request) {
    //Success
  } else {
    //Error
  }
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 07-23-2008, 02:35 AM Re: Problem with Ajax
Super Talker

Posts: 104
Location: http://www.joomladevs.com
Trades: 0
Quote:
Originally Posted by JeremyMiller View Post
I use this...

Code:
  try {
    request = new XMLHttpRequest();
  } catch (trymicrosoft) {
    try {
      request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (othermicrosoft) {
      try {
        request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (failed) {
        request = false;
      }
    }
  }

  if (request) {
    //Success
  } else {
    //Error
  }
Yes this is best way (try and catch) and I am using the same code
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


saurabhj is offline
Reply With Quote
View Public Profile Visit saurabhj's homepage!
 
Reply     « Reply to Problem with Ajax
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.73988 seconds with 12 queries