I'm having a form and using the $.POST for posting it to the some url..
From there i couldn't access the form values. I dont know what the error may be??
The form is like
<form id="registration-form" >
<input type="hidden" name="Profile[fb_uid]" value='1232323'></input>"
<select name="Profile[feet]" id="feet">
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<a class="btnLgBlueGrad" href="#" name="closeModal" id="profileSubmit">Start</a>
</form>
the js call is like this
$( "#profileSubmit" ).click(function() {
$.post("?r=site/addBasicProfile",
function(data){
alert(data); // this is alerting as empty
if(data==1)
window.locatio开发者_开发问答n.href="?r=site/index";
});
});
The actual method which is called is
public function actionAddBasicProfile(){
echo $_REQUEST['profile'];
// when i echo something static it is reflected in the ajax callback function
}
I'm sure the url is correct and ajax request is passed.
That's because you don't pass any data to the $.post(), from the jquery website:
jQuery.post( url, [data,] [success(data, textStatus, jqXHR),] [dataType] )
So you should pass some data to your php script:
$.post("?r=site/addBasicProfile",
$('#registration-form').serialize(), // this will serialize the form data
function(data){
alert(data); // this is alerting as empty
if(data==1)
window.location.href="?r=site/index";
}
);
And as a side note you should use $_POST
to get POST values since $_REQUEST
can also get you the GET values.
or serialize form and also could use lowercase in names.
you need to pass the form parameters as data with the $.post call.
examples @ http://api.jquery.com/jQuery.post/
You can also use ajaxSubmit available with the JQuery forms plugin, which will handle it for you. @ http://jquery.malsup.com/form/
$('#form').ajaxSubmit({ success: handle_success, });
精彩评论