#!/usr/bin/perl
print "Content-type: text/html
";
print qq(<html>
<head>
<script type="text/javascript" src="/jquery.js"></script>
<script>
jQuery(document).ready(function(){
jQuery("#form_lang").submit(function(e){
var str = jQuery(this).serialize();
alert("dfdaf");
jQuery.ajax({
type: "POST",
url:"contacts.pl",
success: function(){
jQuery("#note").ajaxComplete(function(event, request, settings){
if(msg == 'OK')
alert("Your message!");
});
},
});
});
});
</script>
</head>
Here is the form part :
<form id ="form_lang" action="helloworld.pl" method="POST">
<p>Enter Language: </p>
<input type="text" id="lang" name="lang" /><br/>
<p>Enter Description: </p>
<textarea id="lang_desc" name="lang_desc" ></textarea><br/>
<input type="submit" value="submit" />
Here the control goes upto alert("dfdaf").And after that it's being submitted to helloworld.pl...The contacts.pl isnt being referred..Y is that?? how to make a call then ? Thanx in advance
You're not "calling Ajax from Perl".
You're writing Javascript with Perl.
The Javascript will be sent from the server, then executed on the browser.
And I guess the browser isn't finding "contacts.pl".
Q: Are you getting an error message in the browser window (like "404" or "500")?
Q: Do you see anything on the server's error and/or access logs?
When you submit the form, the submit event will fire. That will trigger the submit handler, which will start the Ajax request.
The browser will then submit the form as normal (because nothing is stopping it).
The browser will load a new page, and remove the environment in which the JavaScript was running. The Ajax will be cancelled (it is possible that the request might get through to the server, but the response won't be processed by the browser).
If you want to do stuff when the form is submitted, then do it in helloworld.pl
Use Ajax when you want to communicate with the server without leaving the page.
(You could also cancel for the form submission, then use JS to resubmit it when the Ajax request comes back … but that is overcomplicated and inefficient).