Reputation: 139
I am trying to submit a form using JQuery to a PHP page. But I get the following error when I try to run the script from Chrome:
Uncaught SyntaxError: Unexpected token ; jquery-latest.js;614
Line 614 is part of the GlobalEval function.
globalEval: function( data ) {
if ( data && rnotwhite.test( data ) ) {
// We use execScript on Internet Explorer
// We use an anonymous function so that context is window
// rather than jQuery in Firefox
( window.execScript || function( data ) {
window[ "eval" ].call( window, data );
// **** Uncaught SyntaxError: Unexpected token ; **** //
} )( data );
}
},
This is my code for my form and JQuery submit.
<div class="container create-event">
<form name="new-event" method="post" id="new-event">
Name of the event: <input type="text" name="event-name"></br>
Date of the event: <input type="date" name="date"></br>
Location of the event: <input type="text" name="location"></br>
Description: <textarea cols="50" rows="5" name="description"></textarea></br>
<a href="#" id="event-submit" class="button red">Submit</a>
<script type="text/javascript">
$('#new-event').submit(function() {
$.post(
'post-event.php',
$(this).serialize(),
function(data){
$('#results').html(data);
}
);
return false;
});
$('#event-submit').click(
$(this).parents('form:first').submit();
);
</script>
</form>
<div id="results"></div>
</div>
Then my 'post-event.php' script is this:
<?php
echo "Hello";
?>
Any help is much appreciated.
Upvotes: 0
Views: 329
Reputation: 1239
$('#event-submit').click(
$(this).parents('form:first').submit();
);
After changing the click function into the code below it worked for me.
$('#event-submit').click(function(){
$(this).parents('form:first').submit();
});
You were missing the function() reference.
Upvotes: 5