1

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(){}); 
    });
});

2 Answers 2

3
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();
});​​​​​​​​​​
Sign up to request clarification or add additional context in comments.

3 Comments

and dont forget the return false; at the end!
action only returns the main URL without the GET queries. Any ideas? Will that be through the use of serialize?
Answered my own question... a combination of action and serialize is needed, with a question mark between. Thanks!
0
<form action="something.php" method="POST">

</form>


jQuery('form').submit(function(e){
    e.preventDefault();
    var url = $(this).attr('action');
   ....// rest of code

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.