Getting GET request string in jQuery
suppose I have a form:
<form id="someform" action="some.php" method="get">
<input type="text" name="somename" />
<input type="text" name="oth开发者_开发百科ername" />
...
<input id="submitId" type="submit" value="OK" />
</form>
And I want to get the request string generated by this:
?somename=blabla&othername=blablabla&submit=OK
Can I get this without actually submitting the form?
$('#submitId').live('click', function(e) {
e.preventDefault();
//... what to do here?
});
Another one, if I have the request string, can I put them to the form? (reversed).
Thanks.
Try using http://api.jquery.com/serialize/
$('#submitId').live('click', function(e) {
e.preventDefault();
$('#someform').serialize();
});
try jQuery serialize:
$('#someform').serialize();
I think you want to submit form using jQuery. You can use jQuery.ajax like this:
jQuery('#someform').live('submit',function(e) {
$.ajax({
url: $(this).attr('action'), // get action from form tag
type: 'GET', // GET method
data: $(this).serialize(), // Get form values
success: function( response ) {
alert( response ); // response from action script
}
});
e.preventDefault();
});
Now in some.php
action you can get form values like this:
echo $_GET['somename'];
echo $_GET['othername'];
精彩评论