Reputation: 544
I'm looking to reload part of a page when a form is submitted using GET
method. The following JavaScript runs, though I am unsure of how to get the submitted URL from the form?
I would have thought var link = jQuery(this).attr('GET');
or somethign would return it, and have tried URL
etc... no luck though. Any ideas?
jQuery('form').submit(function(e){
e.preventDefault();
var link = jQuery(this).attr('GET'); //Get the href attribute
alert(link);
history.pushState('data', '', link);
jQuery('#search_main_section').fadeTo(300,0.3,function(){
load(link + ' #search_main_section', function(){ jQuery("#loader").hide();
jQuery('#search_main_section').fadeTo(100,1, function(){});
});
});
Upvotes: 1
Views: 1417
Reputation: 207501
var link = jQuery(this).prop('action');
And if you want the values of the form, you want to use serialize()
Example of using action and searlize with load.
$("#form1").on("submit", function(e) {
e.preventDefault();
var form = $(this);
var action = form.attr("action") || window.location.href;
var formValues = form.serialize();
//example with get
//$.get(action, formValues, function(){ alert("done"); });
//example with load
var url = action + "?" + formValues;
$.load(url + ' #search_main_section', function(){ jQuery("#loader").hide();
});
Upvotes: 3
Reputation: 5283
<form action="something.php" method="POST">
</form>
jQuery('form').submit(function(e){
e.preventDefault();
var url = $(this).attr('action');
....// rest of code
Upvotes: 0