I've seen questions similar to this one, but still didn't find the solution, and this is really wasting my time :(
Here's my controller
public function test() {
print_r($_POST);
return;
}
View
<?php
echo form_open(base_url('go/test'), 'id="update" autocomplete="off" ajax-hidden');
echo form_hidden('id', $id);
?>
<input id="update" name="number" class="spinner" readonly="readonly"
value="<?$=value?>"/>
<?php
echo form_close();
?>
I'm using jQuery to submit the form once the jQuery UI spinner is changed. This is the response:
Array()
-
I must add that other forms in the website work fineSarah– Sarah2013年06月11日 18:35:39 +00:00Commented Jun 11, 2013 at 18:35
-
That input doesn't seem to have a type, should it be type="hidden" ? Probably not the cause.somedev– somedev2013年06月11日 18:39:09 +00:00Commented Jun 11, 2013 at 18:39
-
stackoverflow.com/questions/14201815/… see and checkM Khalid Junaid– M Khalid Junaid2013年06月11日 18:41:20 +00:00Commented Jun 11, 2013 at 18:41
4 Answers 4
Most likely jQuery is not able to get a value to pass over to your Controller because your form and input elements have the same id update
Also <?$=value?> is incorrect syntax. It should be <?= $value ?>
Comments
Also you should use codeingiters post handlers $something = $this->input->post('something');
http://ellislab.com/codeigniter/user-guide/libraries/input.html
Comments
Change your input id to something other than "update"
And change < ?$=value > to < ?=$value >
<input id="myInput" name="number" class="spinner" readonly="readonly" value="<?= $value?>"/>
Comments
I forgot that I changed my ajax handler to work with IE and didn't change the ajax function for this particular form, because this form's response should be hidden, so it uses a different ajax handler.
This is my main submit function:
(function($){
jQuery.fn.ajaxFormSubmit =
function(container, data) {
var url = $(this).attr('action');
$.ajax({
url: url,
type: "POST",
data: data,
dataType: "html",
success: function(msg) {
$(container).html(msg);
}
});
return this;
};
})(jQuery);
I used to serialize the form data inside this function but then I realized it didn't work for IE, the only solution was to serialize the form data before doing anything else!
Here are the 2 functions I'm using:
$('form[ajax]').live('submit', function(e){
e.preventDefault();
var data = $(this).serialize();
var container = $(this).attr('cont');
if (typeof container == 'undefined' || container == false) {
container = '.#ajax';
}
$(container).html('<img src="public/images/ajax.gif"/>');
$(container).fadeIn('fast');
$(this).ajaxFormSubmit(container, data);
});
$('form[ajax-hidden]').live('submit', function(e){
e.preventDefault();
var data = $(this).serialize();
var container = '';
$(this).ajaxFormSubmit(container, data);
});
The second function simply didn't have the data variable. So I added it. Hope this can help someone.