Reputation: 946
I'm trying to post a form via jQuery .post()
, and it's not working as it should. I'm getting nothing from the console, and it's quite frustrating. Requesting help from an experienced JS user. Thanks a lot for all of your help!
NOTE: This form is constructed with CodeIgniter, and posts perfectly fine using its Form Helper and HTML conventional routes. The JS/jQuery method is what is not working properly.
Form:
<form class="nice custom" id="create_form">
<h3>Create Event</h3>
<label for="intention"><strong>Intention:</strong></label>
<?php $intention_attributes='style="width: 100%; " class="show-on-phones" id="intention_dropdown"'; ?>
<?php echo form_dropdown('intention', $intention, 'Select Intention', $intention_attributes ); ?>
<div class="custom dropdown show-on-desktops" style="width: 100%; ">
<a href="#" class="current">Select Intention</a>
<a href="#" class="selector"></a>
<ul style="width: 100%; ">
<li>Select Intention</li>
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
<li>Option 4</li>
<li>Option 5</li>
</ul>
</div>
<label for="action"><strong>Action:</strong></label>
<?php echo form_input($action); ?>
<label for="date_of_event"><strong>Date:</strong></label>
<?php echo form_input($date_of_event); ?>
<label for="repeat_event"><strong>Repeat:</strong></label>
<?php $repeat_event_attributes='style="width: 100%; " class="show-on-phones" id="repeat_event_dropdown"'; ?>
<?php echo form_dropdown('repeat_event', $repeat_event, 'Never', $repeat_event_attributes); ?>
<div class="custom dropdown show-on-desktops" style="width: 100%; ">
<a href="#" class="current">Never</a>
<a href="#" class="selector"></a>
<ul style="width: 100%; ">
<li>Never</li>
<li>Every Day</li>
<li>Every Week</li>
<li>Every Two Weeks</li>
<li>Every Month</li>
<li>Every year</li>
</ul>
</div>
<label for="end_repeat_event"><strong>End Repeat:</strong></label>
<?php echo form_input($end_repeat_event); ?>
<br />
<input style="width: 100%; " type="submit" name="submit" class="medium radius blue button" value="Create" id="create_button" />
</form>
JavaScript:
// Submit Create Form
$('#create_form').live('submit', function() {
var data = $('#create_form').serialize();
var url = $(this).attr('action');
$.post(url, data, function() {
document.location.reload();
});
return false;
}); // End
Upvotes: 1
Views: 81
Reputation: 7135
Also, press the black dot button on the top of the console output tab (webkit browsers). This will preserve log messages between page loads.
Upvotes: 0
Reputation: 1935
Try changing the name of your submit button to btnSubmit. I've had issues in the past with naming the submit button submit.
Thanks,
Upvotes: 0
Reputation: 268374
Your form has no action value:
<form class="nice custom" id="create_form">
Even though you're attempting to get one:
var url = $(this).attr('action');
Also, avoid using $.live
from here on out:
As of jQuery 1.7, the
.live()
method is deprecated. Use.on()
to attach event handlers. Users of older versions of jQuery should use.delegate()
in preference to.live()
.
Upvotes: 1