PDA

View Full Version : Ajax problem



Usagi
10-11-2007, 02:36 AM
1) Script Title:
Basic Ajax Routine (get & Post)
2) Script URL (on DD):
http://www.dynamicdrive.com/dynamicindex17/ajaxroutine.htm
3) Describe problem:

When I follow the example code:
<head>
//Step 1: Install the routine script:
<script src="text/javascript" src="ajaxroutine.js">
//CREDIT NOTICE GOES HERE
</script>
</head>

<body>

<script type="text/javascript">
//Step 2: Define a "callback" function to process the data returned by the Ajax request:
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}

//Step 3: Invoke the Ajax routine method to make the desired Ajax request.
ajaxpack.getAjaxRequest("example.htm", "", processGetPost, "txt")
</script>


all I get is a blank page:

http://testingsite.prose-n-poetry.com/scripts/test.htm

Usagi
10-11-2007, 02:48 AM
I found the error:

<!--Step 1: Install the routine script: -->
<script src="text/javascript" src="/javascripts/ajaxroutine.js">

it should be:
<script type="text/javascript" src="/javascripts/ajaxroutine.js">

This is an error on the DD page.

jason_rmh
10-18-2007, 03:29 PM
Was searching for some help and thought i would add to this thread as its sort of relevant...

Ive been using the basic ajax routine from DD, like the one listed above by Usagi.

Its has been working fine. However, ive noticed a problem that only seems to occur in IE6 (SP1).

I use the 'ajaxpack.postAjaxRequest()' routine to send a form to an asp (vbscript) page, which then sends back a reply, depending on the reply, a certain action will be taken.

In IE6 sp2, IE 7, firefox etc, the reply comes back fine.
In IE6 SP1 on the first message gets through. All subsequent messages dont seem to send.
The ajaxpack.postAjaxRequest seems to send, but the asp message never gets the request. Server logs show that the asp page is not being called. So where is the request going??

And it only happens in IE6 SP2!! All other browsers work fine.

On the processmessage() function, the myajax.readyState never seems to get to 4 (completed), and by the time is does, 2mins or so have passed. By this time, the myajax.status is way greater than 200 and so the response does not get processed.

:confused: Any help appreciated. :confused:

ddadmin
10-19-2007, 06:45 AM
Sounds like a caching issue. Inside ajaxroutine.js, try setting the below var to 1:


ajaxpack.addrandomnumber=1 //Set to 1 or 0. See documentation.

p.s: In the future, please start a new thread when asking your own question, even if it's regarding the same script as another thread's.

jason_rmh
10-19-2007, 08:18 AM
Sounds like a caching issue. Inside ajaxroutine.js, try setting the below var to 1:


ajaxpack.addrandomnumber=1 //Set to 1 or 0. See documentation.
p.s: In the future, please start a new thread when asking your own question, even if it's regarding the same script as another thread's.

Hi,
thanks for ya reply.
This change made no difference to the problem.
Any ideas welcome, im at my wits end with this :confused:

Thanks

ddadmin
10-19-2007, 08:52 AM
Please post a link to the page on your site that contains the problematic script so we can check it out.

jason_rmh
10-19-2007, 11:22 AM
Solved the problem. Hope this will help someone else...
After painfully investigating each bit of code (2.5 days so far), i realised that the POST was causing the problem.
So i changed from POST to GET


var poststr=createpoststring()
if (poststr != "")
{
ajaxpack.postAjaxRequest("example.htm", poststr, processGetPost, "txt")
}

to


var poststr=createpoststring()
if (poststr != "")
{
ajaxpack.getAjaxRequest("example.htm", poststr, processGetPost, "txt")
}


Solving the problem. Although i am sending data from a form, it is not a huge amount in data terms, and have tested it with upto 1000chrs, which is plenty for my purpose.

I am unsure what the POST is causing problems, but its not a problem for me to use GET, i realise this may not be an option in certain implementations.


Thanks
Jason:D

ddadmin
10-19-2007, 09:40 PM
Thanks for the update.