PDA

View Full Version : Anyone good with ajax/ javascript?



Mentor
30-05-2006, 05:32 PM
Basicaly my ajax news system for tb5 works perfectly in firefox but ****s up in IE. As i cant realy be arsed to hunt aorund for hours looking for whats wrong, when chances are its stairing me obviosly in the face, im asking here to see anyone with a freash approach and figure out the problem quickly.

The javascript code is as below:


var target ;

function a_edit(id){
target = 'N_' + id;
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { // DontWork
}
xmlhttp.onreadystatechange = b_edit;
xmlhttp.open("GET", '####&a=addform&id=' + id);
xmlhttp.send(null);

}
function b_edit(){
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
document.getElementById(target).innerHTML = xmlhttp.responseText;
}
}
function c_edit(id){
// Get Data
var title = document.getElementById("N" + id + "_title").value;
var cat = document.getElementById("N" + id + "_Cat").value;
var update = document.getElementById("N" + id + "_time").checked;
var news = document.getElementById("N" + id + "_NewsItem").value;

xmlhttp.onreadystatechange = d_edit;
xmlhttp.open("POST", '####&a=save&id=' + id + '', true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("title=" + title + "&cat=" + cat + "&update=" + update + "&news=" + news + "");

}
function d_edit(){
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

var rsp = xmlhttp.responseText;
// Spit Id and responce
var rsp2 = rsp.split('||--||');
var loc = 'N_' + rsp2[0];
//Write responce to ID
document.getElementById(loc).innerHTML = rsp2[1];


}
}
var adin = 0;
function n_Add(){

if(adin== 1) {
}
else {
// Load Ajax form for New news
try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");} catch (e) { // DontWork
}
xmlhttp.onreadystatechange = n_Add2;
xmlhttp.open("GET", '####&a=New_addform');
xmlhttp.send(null);
}
}
var cur;
function n_Add2(){
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
cur = document.getElementById('addSpace').innerHTML
document.getElementById('addSpace').innerHTML = xmlhttp.responseText + cur;
adin = 1;
}
}
function n_Add3(){
//
var title = document.getElementById("New_title").value;
var cat = document.getElementById("New_Cat").value;
var news = document.getElementById("New_NewsItem").value;

xmlhttp.onreadystatechange = n_Add4;
xmlhttp.open("POST", '####&a=addme', true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlhttp.send("title=" + title + "&cat=" + cat + "&news=" + news + "");

}
function n_Add4(){
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {

document.getElementById('addSpace').innerHTML = xmlhttp.responseText + cur;
adin = 0;
}
}

function delete_N(id) {
if (confirm('Are you sure you want to delete this News Item?')) {
// Ajax remove post
xmlhttp.open("GET", '####&a=del&id=' + id);
xmlhttp.send(null);
// Make gone
document.getElementById('N_' + id).innerHTML = "";
}
else {
// Cancil remove prot
alert ('Ok, no action has been taken');
}
}

To be on the safe side i #### the urls until i get around to checking them security wize

the code it works on


<div align="left">
<div style="padding:6px"><a href="javascript:n_Add();">ADD NEWS BUTTON</a></div><br />

<div id="addSpace"></div>

<div id="N_6">

<a href="javascript:a_edit(6);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(6);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>


<img src="http://thybag.co.uk/mkportal/modules/gallery/album/t_a_348.jpg" alt="Mentor Avitar" width="106" height="150" style="padding:4px; float:left; position:relative; z-index:4;">

<h3><a href="#">Netscape Firefox Add</a></h3>

<div style="padding:0px 0px 5px 0px;">

<div align="left">
Lets see about them there perms ey?<br>My <br>av<br>it <br>ar<br>Its a <br>little<br>big for this<br>new system maybe...<br><br>i think.. or do i <!--emo&:/--><img src='http://thybag.co.uk/forum/html/emoticons/hmm.gif' border='0' style='vertical-align:middle' alt='hmm.gif' /><!--endemo--> <!--emo&:)--><img src='http://thybag.co.uk/forum/html/emoticons/smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /><!--endemo--> YOu suck!

</div>
<div style="background-color:#CCCCCC; padding:2px;">
<div style=" float:right; font-weight:bold;">
0 <a href="#">Comments</a>
</div>
By <a href="forum/index.php?showuser=66"><strong>Mentor</strong></a> at 6:24 - 06/04/2006
</div>

</div>

</div>


<div id="N_4">

<a href="javascript:a_edit(4);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(4);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>


<img src="http://img107.exs.cx/img107/1092/ufo6ld.gif" alt="Bag Avitar" width="75" height="53" style="padding:4px; float:left; position:relative; z-index:4;">
<h3><a href="#">Shizzle</a></h3>

<div style="padding:0px 0px 5px 0px;">

<div align="left">
I think we have a working news system here! <br>I iz like well Chuffed with dat achivement Ey <!--emo&:D--><img src='http://thybag.co.uk/forum/html/emoticons/biggrin2.gif' border='0' style='vertical-align:middle' alt='biggrin2.gif' /><!--endemo--><br><br>Uz also smellzz

</div>
<div style="background-color:#CCCCCC; padding:2px;">
<div style=" float:right; font-weight:bold;">
0 <a href="#">Comments</a>
</div>
By <a href="forum/index.php?showuser=1"><strong>Bag</strong></a> at 12:07 - 05/04/2006
</div>

</div>

</div>


<div id="N_1">

<a href="javascript:a_edit(1);"><img src="http://thybag.co.uk/forum/style_images/bag/p_edit.gif" alt="Edit" style="border:0; float:right; position:relative;"></a><a href="javascript:delete_N(1);"><img src="http://thybag.co.uk/forum/style_images/bag/p_delete.gif" alt="Delete" style="border:0; float:right; position:relative;"></a>


<img src="http://img107.exs.cx/img107/1092/ufo6ld.gif" alt="Bag Avitar" width="75" height="53" style="padding:4px; float:left; position:relative; z-index:4;">
<h3><a href="#">Thybag Ajax News Engine Online</a></h3>

<div style="padding:0px 0px 5px 0px;">

<div align="left">
Yes, i think ive finaly managed to get this thing working. Thybags new system can now be edited without any refreshing, directly where it is via the edit button on the right of each artical. So far the forum parser is working perfectly and provideing the smilys and BB code as it is needed.<br><br>Wooot is my responce <!--emo&:D--><img src='http://thybag.co.uk/forum/html/emoticons/biggrin2.gif' border='0' style='vertical-align:middle' alt='biggrin2.gif' /><!--endemo--><br>PS. I am naked... really naked!<br>PSS. No wait, Thats not me. Just ryan... Why is ryan naked in my room?<br>PSSS. Feel the wind!<br>PSSSS. *Swipes Fan* MINE! *throws tantrum*<br>PSSSSS. I like Pie an i cannot lie!

</div>
<div style="background-color:#CCCCCC; padding:2px;">
<div style=" float:right; font-weight:bold;">
0 <a href="#">Comments</a>
</div>
By <a href="forum/index.php?showuser=1"><strong>Bag</strong></a> at 9:41 - 04/04/2006
</div>

</div>

</div>











<div style="padding:12px">Pages: 1 2 3 4 5 6 .</div> </div></div>
</div>
</div></div></div></div></div></div></div></div>

</div><br>
<br>

Any obvios errors or idiotc stuff in there? or something wrong that would cause problems with IE copatablty?

Thanks for any help

-::Mr.Dave::-
30-05-2006, 05:48 PM
what is ajax?

Recursion
30-05-2006, 06:08 PM
i form of coding like PHP and HTML

Tomm
30-05-2006, 06:10 PM
i form of coding like PHP and HTML

Actually its just javascript.

Recursion
30-05-2006, 06:13 PM
still is a form of code as JS is a form of code...

Tomm
30-05-2006, 06:14 PM
You said AJAX is a form of coding witch is not totally true since its a name for a way of using javascript.

Recursion
30-05-2006, 06:20 PM
lets go back on topic, we are both right :)

-::Mr.Dave::-
30-05-2006, 06:31 PM
[off topic] Numark are u still a web designer for me? [/off topic]

Sygon.
30-05-2006, 06:39 PM
If i could iwould bag i dont understand half of that :@ Oh well ill learn :D

Recursion
30-05-2006, 06:41 PM
[offtpoic] Im not a web designer im a Site Techie :P, you just have to catch me on MSN [/offtopic]

Luckyrare
30-05-2006, 06:43 PM
Hey Mentor, the only person I know on this forum that knows AJAX is Nets. Your better just asking him.

Good luck ;)

Mentor
30-05-2006, 06:47 PM
Hey Mentor, the only person I know on this forum that knows AJAX is Nets. Your better just asking him.

Good luck ;)
true, but he doesnt appear to be online at the moment, so i was hopeing someone else would maybe be able to see the problemo in the mean time.. meh, i usealy end up haveing to spend hours figuering this stuff out, danm lously shortcuts!

Tomm
30-05-2006, 08:16 PM
Meh i know a bit of AJAX, but not a lot so I cant really help.

Splinter
31-05-2006, 09:19 AM
Hmmm I only know basic ajax but from what I have learned there are two Internet explorer xmlhttprequests which are
new ActiveXObject("Msxml2.XMLHTTP");
and
new ActiveXObject("Microsoft.XMLHTTP");
and as far as i have seen you have only used the second one.. that might work. But this is the most advanced ajax I have ever seen :P

Tomm
31-05-2006, 09:23 AM
If this helps heres some code from the AJAX side of my radio panel:


var page_request = false
if (window.XMLHttpRequest)
page_request = new XMLHttpRequest()
else if (window.ActiveXObject){
try {
page_request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch (e){
try{
page_request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}

Splinter
31-05-2006, 09:25 AM
thats basically what I meant :P

Dan Williamson.
31-05-2006, 11:47 AM
Yes it is the ActiveX you should do this.


/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new XMLHttpRequest();
if(xmlHttp)alert("otherBrowser");
} catch (trymicrosoft) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
if(xmlHttp)alert("Msxml2");
} catch (othermicrosoft) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
if(xmlHttp)alert("Microsoft");
} catch (failed) {
xmlHttp = false;
}
}
}
@end @*/

Want to hide these adverts? Register an account for free!