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
new to AJAX.. how do i do this?
Old 04-08-2010, 12:26 PM new to AJAX.. how do i do this?
Junior Talker

Posts: 3
Trades: 0
hi,

i recently found this code that i need for my file sharing website. i know nothing about AJAX though, does it work like javascript? all i have is a simple HTML form and i need this function to be called when the form is sent.
HTML Code:
/* A pretty little hack to make uploads not hang in Safari. Just call this
 * immediately before the upload is submitted. This does an Ajax call to
 * the server, which returns an empty document with the "Connection: close"
 * header, telling Safari to close the active connection. A hack, but
 * effective. */

function closeKeepAlive() {
  if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
    new Ajax.Request("/ping/close", { asynchronous:false });
  }
}
thanks for any help!

Last edited by chrishirst; 04-08-2010 at 02:22 PM..
mm2703 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-09-2010, 09:59 PM Re: new to AJAX.. how do i do this?
badams's Avatar
Skilled Talker

Latest Blog Post:
Dum Skype Firefox plugin
Posts: 69
Name: Barry Adams
Location: London
Trades: 0
AJAX is a javascript library for allowing a web page to communicate back to the web server it came from, and so partially update the page is required. To get you function called you submit a form use.

<FORM action=".." METHOD="post" onSubmit('closeKeepAlive();true;')>

Your also need the Ajax library on your server and to import the library at the beginning of your page.
<script type="text/javascript" src="/ajax.js"></script>
__________________

Please login or register to view this content. Registration is FREE
@
Please login or register to view this content. Registration is FREE
(320+ Subjects)
badams is offline
Reply With Quote
View Public Profile Visit badams's homepage!
 
Old 04-10-2010, 05:40 PM Re: new to AJAX.. how do i do this?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
AJAX is a javascript library for allowing a web page to communicate back to the web server it came
Nope...
Ajax means "Asychronous Javascript And Xml".
this acronym regroups a bunch of techniques used to communicate from a browser to a server in an asynchronous way (when the page is loaded).
You may have a library that is named ajax, but ajax is not that library....

As javascript is handled by the browser, you have several framework here to wipe those differences away, and ease the development by allowing plugins or module to extend the framework.
Like jquery (http://jquery.com/).

@mm2703, to answer your question, Ajax is javascript.
Like badams showed you, using an "onsubmit" event on your form should be ok, but you probably need to modify the function to return a true value.
Quote:
Note that in order to cancel the submit event, the onSubmit should be in the form onSubmit="return expression". "return" indicates that the value of the expression should be returned to the submit routine. If the expression evaluates to false, the submit routine is canceled; if it is true, the submit routine goes forward.
HTML Code:
<script type="text/javascript">
function closeKeepAlive() {
  if (/AppleWebKit|MSIE/.test(navigator.userAgent)) {
    new Ajax.Request("/ping/close", { asynchronous:false });
  }
  return true;
}
</script>
<FORM METHOD="post" onSubmit="return closeKeepAlive()">
  <input type="submit" value="send"/>
</form>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-11-2010, 01:10 PM Re: new to AJAX.. how do i do this?
chizza's Avatar
Junior Talker

Posts: 2
Name: 1
Location: Lichfield
Trades: 0
its quite funky
we just put it on our site

makes the address bar do funny things

but i like it

<link drop removed>
__________________
chris -
Please login or register to view this content. Registration is FREE

web services with service

Last edited by chrishirst; 04-11-2010 at 03:37 PM..
chizza is offline
Reply With Quote
View Public Profile
 
Old 11-12-2010, 10:36 PM Re: new to AJAX.. how do i do this?
Backslider's Avatar
Experienced Talker

Posts: 40
Trades: 0
This function should not be called onsubmit, but rather before the form is submitted.

It is a hack to fix a problem with Safari/Mac...... dating back to 2005!!!! (still not fixed in 2010) That is, multipart form submits fail completely with this combination (hence the reason it should be called *before* a form submit).

Wish old Jobs would spend more time fixing his own bugs before dumping on everybody else.

The easiest way to implement Ajax is to use a library such as jQuery. The sample posted above uses the Prototype library.

If using PHP on your site, the function must make an Ajax call to a file with the following in it:

Code:
<?php header("connection: close"); ?>
Use whatever is appropriate for your programming language.

mm2703 - The code you posted won't work as is. The path for the Ajax request must be set correctly, eg.

Code:
new Ajax.Request("cc.php", { asynchronous:false });
Then you need to create a file named cc.php and place in that the first code snippet I posted. The function you posted requires the Prototype library, so you need to download that and call it into your page. The "new Ajax.Request()" is how Prototype sends an Ajax request.

I would lean toward submitting your form using javascript, because you must execute the closeKeepAlive() function before the form itself is submitted. Alternatively you could try the following on your form page, which again is Prototype dependent code:

Code:
<script type="text/javascript">
document.observe("dom:loaded", function() {
 closeKeepAlive();
});
</script>
This will fire the function as soon as your form page has loaded, which should work.

Last edited by Backslider; 11-13-2010 at 02:45 AM..
Backslider is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to new to AJAX.. how do i do this?
 

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 1.19373 seconds with 12 queries