im loading a external page from flowplayer overlay and im trying to submit a form in that page via ajax, and its reloading the page.
when i browse the file directly it works fine but when its in the overlay it reloads the page on submit.
is there anything to configure that it will load the jquery file and submit via ajax?
thanks
this is the code
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script>
$(function(){
$("#JqAjaxForm").submit(function(){
dataString = $("#JqAjaxForm").serialize();
$.ajax({
type: "POST",
url: "mailto_friend.cfm",
data: dataString,
dataType: "json",
success: function(data) {
if(data.email_check == "invalid"){
$("#message_ajax").html("<div class='errorMessage'>Sorry " + data.name + ", " + data.email + " is NOT a valid e-mail address. Try again.</div>");
} else {
$("#message_ajax").html("<div class='successMessage'>" + data.email + " is a valid e-mail address. Thank you, " + data.name + ".</div>");
}
}
});
return false;
});
});
</script>
</head>
<body>
<form id="JqAjaxForm">
<fieldset>
<legend>jQuery.ajax Form Submit</legend>
<p><label for="name_ajax">Name:</label><br />
<input id="name_ajax" type="text" name="name_ajax" /></p>
<p><label for="email_ajax">E-mail:</label><br />
<input id="email_ajax" type="text" name="email_ajax" /></p>
<p> <input type="submit" value="Submit" /></p>
</fieldset>
</form>
<div id="message_ajax"></div>
</body>
</html>
this is the exact code and it has the ready function
<div id="result">
<form id="testForm" >my data
</form>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#testForm").submit(sendForm)
});
function sendForm() {
$.post('mypage.cfm',$("#testForm").serialize(),function(data,status){
$("#result").html(data);
return false;
});
return false;
}
</script>
It appears to be caused by having the jQuery code invoked before the HTML is ready.
If you move your script to the bottom of the HTML file it will work fine.
Alternately, you can use the jQuery .ready() method to delay execution.
UPDATE: I’d wrap all the javascript in the document ready function so that it delays execution until the DOM is ready. I cannot test further without the mailto_friend.cfm file.