Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Not working in FF/Chrome, working in IE

innerHTML

  • Please log in to reply
17 replies to this topic

#1 fedlerner

fedlerner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 10 March 2011 - 04:05 PM

Hi guys!

I've the following AJAX code:
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var site_url= encodeURI(document.getElementById('site_url').value);
var site_type = encodeURI(document.getElementById('site_type').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?site_url='+site_url+'&site_type=' +site_type+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send(null);
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Site added:'+response;
}
}

This code works to insert a MySQL record to a Database using AJAX. It works fine on IE, but it's not working on FF or Chrome. When I test it on FF/Chrome, i just get the text "Just a second..." and it doesn't advance from there.
I don't really know AJAX, so I don't know where the issue is. I would really appreciate your help.

Regards,
Federico.-
  • 0

#2 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 11 March 2011 - 01:01 AM

http.send(null);
I don't think you need something mandatory over there. Try this
XHR.send()
where XHR = xml httprequest object
  • 0

#3 fedlerner

fedlerner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 11 March 2011 - 01:27 AM

Hi gokuakmes,

Thanks for helping me.
From what you've said, I should replace "http.send(null);" for "XHR.send();".. But where should I add/replace "xhr = new XMLHttpRequest();" ?... Sorry for this noob question, I'm a total begginer on AJAX.
Could you tell me how the code will stay like ? (the lines that need editing)

Regards,
Federico.-
  • 0

#4 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 11 March 2011 - 02:16 AM

Lol see my previous response
  • 0

#5 fedlerner

fedlerner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 11 March 2011 - 04:38 AM

Hi,

Yes, but I don't know where I should put the line:
xhr = new XMLHttpRequest();

Thanks,
Federico.-
  • 0

#6 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 11 March 2011 - 06:47 AM

Hey, sorry for not responding soon but here is the complete code
/* ---------------------------- */
/* XMLHTTPRequest Enable */
/* ---------------------------- */
function createObject() {
var request_type;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_type = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_type = new XMLHttpRequest();
}
return request_type;
}

var http = createObject();

/* -------------------------- */
/* INSERT */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */
var nocache = 0;
function insert() {
// Optional: Show a waiting message in the layer with ID login_response
document.getElementById('insert_response').innerHTML = "Just a second..."
// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.
var site_url= encodeURI(document.getElementById('site_url').value);
var site_type = encodeURI(document.getElementById('site_type').value);
// Set te random number to add to URL request
nocache = Math.random();
// Pass the login variables like URL variable
http.open('get', 'insert.php?site_url='+site_url+'&site_type=' +site_type+'&nocache = '+nocache);
http.onreadystatechange = insertReply;
http.send();
}
function insertReply() {
if(http.readyState == 4){
var response = http.responseText;
// else if login is ok show a message: "Site added+ site URL".
document.getElementById('insert_response').innerHTML = 'Site added:'+response;
}
}

  • 0

#7 gokuajmes

gokuajmes

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 483 posts

Posted 11 March 2011 - 06:48 AM

Hey could you see my previous code
  • 0

#8 fedlerner

fedlerner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 11 March 2011 - 12:00 PM

Hi,

Yes. I've copied and pasted the code you've provided, but it still hangs at "Just a second" on both FF and Chrome.

Regards,
Federico.-
  • 0

#9 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 12 March 2011 - 10:37 AM

Tell us what these alerts give :)

function insertReply() {
  alert(http.readyState + " & " + http.status);
  if(http.readyState == 4){
  var response = http.responseText;
  // else if login is ok show a message: "Site added+ site URL".
  document.getElementById('insert_response').innerHTML = 'Site added:'+response;
}

long shot:
change
http.open('get', 'insert.php?site_url='+site_url+'&site_type=' +site_type+'&nocache = '+nocache);
into
http.open('get', 'insert.php?site_url='+site_url+'&site_type=' +site_type+'&nocache = '+nocache[B], true[/B]);
However I suppose it defaults to true.
  • 0

#10 fedlerner

fedlerner

    CC Newcomer

  • Just Joined
  • PipPip
  • 15 posts

Posted 12 March 2011 - 04:24 PM

On IE: An alert message opens with the message "4 & 200".
On FF/Chrome: It seems the insertReply funcion never gets executed, as there's no alert message.

Adding the line with "true" at the end doesn't seem to work either.
  • 0

#11 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 13 March 2011 - 01:52 AM

Wow, that's very weird. Even if the target page doesn't exist or the server is offline, you would still get messages with readystates and statuses. :blink:
Can you right click in chrome choose 'inspect elemen' click the script tab, and see if there is anything red there (error message)?
  • 0

#12 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 13 March 2011 - 04:19 AM

You may want to click on Tools: Error Console and see if there are any error messages in FireFox.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download