Author Topic: AJAX and browsers  (Read 2100 times)

0 Members and 1 Guest are viewing this topic.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
AJAX and browsers
« on: August 25, 2009, 06:44:59 am »
Ok, I'm getting a grasp of how all this PHP, MySQL, AJAX stuff works. The syntax is much like that of normal programming (except for all those built in functions) and there's a lot of variables being passed around and so on but that's no problem.

Anyway, I got AJAX working, but firefox and internet explorer behave differently. I have a button + a text field which I update with the time as soon as I press the button. Firefox updates every time the button is pressed. IE updates only once (if I open a new IE with that page it can be updated sometimes). Is this a cache problem?
Heckling is an art, and game hacking a science.

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: AJAX and browsers
« Reply #1 on: August 25, 2009, 10:12:20 pm »
yep
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #2 on: August 26, 2009, 12:56:08 am »
Lol. And how do you solve it?
Heckling is an art, and game hacking a science.

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: AJAX and browsers
« Reply #3 on: August 26, 2009, 02:15:22 am »
several ways .. simplest is use post instead of get
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #4 on: August 26, 2009, 09:28:58 pm »
Ya, I passed some dummy parameter with POST and IE seems to work now. Thanks.
Heckling is an art, and game hacking a science.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #5 on: August 26, 2009, 11:52:12 pm »
Ok, another problem.

I don't want to create a new ajax object every time I press a button. (Or do I have to do that?)

So I have this init function:
Code: [Select]
function initAJAX()
{

var ajaxRequest;  // magic variable

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;
}
}
}

return ajaxRequest;
}

It returns the ajaxRequest object, or whatever it is.

In my html header source it looks like this:
Code: [Select]
<script src="ajaxinit.js">
ajaxRequest=initAJAX();
</script>
(maybe this should be in the body?)


Code: [Select]
<form name="testform">
   <input name="test_button" type="button" onClick="ajaxFunction(ajaxRequest);" value="Test" />
   
   <input name="testbox" type="text" id="testboxid"/>
</form>

ajaxFunction handles the Ajax update of a text field displaying the time, and takes ajaxRequest as a param.

But this doesn't seem to work. Does the scope of the ajaxRequest variable end after </script>?
Heckling is an art, and game hacking a science.

ZOldDude

  • The Unknown Rank!
  • Administrator
  • MasstKer
  • *
  • Posts: 20874
  • Old School TKC
    • View Profile
    • Admin
Re: AJAX and browsers
« Reply #6 on: August 27, 2009, 02:10:12 am »
I found this:
http://codingforums.com/showthread.php?p=858342   :icon_laugh  :wink2

Is this what you wanted to know (the sample code has your " </scripts> " in it) ?
Quote
When using global variables and ajax, you need to re-assign them on each request, because when RadAjax starts an Ajax request, it will dispose the old object to minimize the chance for memory leaks. If you do not reassign the global variable you will end up with the old non-functional disposed object after the ajax request returns. Here is a sample code that will share more light on the matter:

http://www.telerik.com/help/aspnet/ajax/ajxreitinvariable.html

*While we crash and burn, small, low tech, agrarian societies such as the Hmong in the mountains of Laos will continue on without so much as blinking an eye.*

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #7 on: August 27, 2009, 02:28:01 am »
Quote
I found this:

Lol... :icon_laugh

I'm not the only one with that nick, but yeah I regged myself on 3 web development forums today.


Not sure about that code. It's for ASP etc.
Heckling is an art, and game hacking a science.

ZOldDude

  • The Unknown Rank!
  • Administrator
  • MasstKer
  • *
  • Posts: 20874
  • Old School TKC
    • View Profile
    • Admin
Re: AJAX and browsers
« Reply #8 on: August 27, 2009, 02:36:09 am »
Well...I am not sure at all because it has been so many decades that I myself have done anything.
It just at a fast glance seem to talk about global variables and I thought that was what you had going on/asking about.

I am really tired,worked all day at the country government center and have to go up on a ladder to paint for this lady outside in 100F heat in about an hour.
I would rather have a couple of cold beers and take a nap.



*While we crash and burn, small, low tech, agrarian societies such as the Hmong in the mountains of Laos will continue on without so much as blinking an eye.*

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #9 on: August 27, 2009, 03:31:30 am »
Found some errors in the code above. But I'll try a different approach. Found some code that looks promising.

Good luck with the paint  :icon_biggrin2
Heckling is an art, and game hacking a science.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #10 on: August 27, 2009, 04:27:49 am »
Code: [Select]
document.getElementById(id).innerHTML = 'Loading...<br />';

Unknown runtime error in IE.

It's ok with Firefox.
Heckling is an art, and game hacking a science.

MrMedic

  • MasstKer
  • ********
  • Posts: 8900
  • programmer/dev/software engineer
    • View Profile
Re: AJAX and browsers
« Reply #11 on: August 27, 2009, 01:09:56 pm »
what exactly is the end goal ? and why have you chosen to use ajax ?
EnCoded Message: i3iy9yl8kr2xf3g2Txs3pr6ye3ya7jg5ty2z

https://www.youtube.com/watch?v=62_7-AYfdkQ
you need a paypal account for the private versions.

Website:
http://bit.ly/medic101

Teamspeak 3: 85.236.101.5:10157

[TKC]Anothercheater

  • Heckler Apprentice
  • ****
  • Posts: 1349
    • View Profile
Re: AJAX and browsers
« Reply #12 on: August 27, 2009, 02:27:07 pm »
Use a aJavascript-Framework and save time: http://en.wikipedia.org/wiki/Comparison_of_JavaScript_frameworks

My recommondation: Prototype (http://www.prototypejs.org/api)

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #13 on: August 27, 2009, 05:15:47 pm »
The primary goal is to learn this stuff, and AJAX has some nice real-time features. So my goal here is to make a real time calculator with a lot of forms.

Not sure about frameworks, because they change a lot and eventually you need to learn another one. I want to learn the basics first before I use that kind of things.
« Last Edit: August 27, 2009, 06:43:09 pm by Mullah Omar »
Heckling is an art, and game hacking a science.

M. O.

  • Administrator
  • MasstKer
  • *
  • Posts: 9185
    • View Profile
    • http://www.tkc-community.net
Re: AJAX and browsers
« Reply #14 on: August 27, 2009, 07:12:04 pm »
Code: [Select]
<?php
echo "<script type='text/JavaScript'>";
echo 
"document.getElementById('testboxid').value='hehe';";
echo 
"</script>";
?>




I call this function with AJAX. I'll be changing hehe to date() later, to get a value that changes all the time. But for that to work this is the first step.

Code: [Select]
<input name="test_button" type="button" onClick="ajaxRequest('test.php', 'testboxid', 'POST');" value="Test" />

Firebug says this was the response:
Code: [Select]
<script type='text/JavaScript'>document.getElementById('testboxid').value='hehe';</script>
However, testbox doesn't update with hehe. But if I just write echo "hehe" and change the
Code: [Select]
ajaxRequest('test.php', 'testboxid', 'POST');
to

Code: [Select]
ajaxRequest('test.php', 'divid', 'POST');
the text at divid updates.
Heckling is an art, and game hacking a science.