Question

I'll be short I have this function

$("#JqPostForm").submit(function(e){    
    e.preventDefault();  
    $("#despliegaresultados").empty();
    $("#paginacion").empty();
    $.post("php/prueba.php", $('#JqPostForm').serialize(),

    function(data)
    {
        $.each(data, function(i, item)
        {
            total= item.total;
            datos = item.datos;
        });

        //is doing something here 

    });
}, "json");

with this html

<html>
.....
   <form>
       <input type="text" name="nombre">
       <input type="submit"> 
   </form>
......
</html>

and well it works fine, send and receive post data with json format, my problem is that when i try to save the form in a different html and then retrieve it through a button or something, my call is done with "GET" params and i have no idea why.

I have read the .load() from jquery doc, also many post from this site but i don't seem to find any information, i also want to mention that i know .load is by default get, i send some parameters to make it post, this is how i get the form from an external archive

$('#target').load('php/searchForm.html',{algo:'algo'});

then my form is loaded now on my html, but when i submit it my call changes to "GET". pd. excuse my english i'm not american neither english thanks.

Was it helpful?

Solution 3

after so much looking for i came with this solution jQuery load relaoding content in div via form submit in div

finally the solution, my problem was solved this way, i moved both files, "index" and "externalForm" to the same directory, both of them on header had and voila i could load an external form and then use it

OTHER TIPS

GET is the default way to send a form, and your form is probably submitted the regular way and not with javascript as there are syntax errors, and if the form is inserted dynamically you'll need delegated event handlers:

$('#target').on('submit', '#JqPostForm', function (e) {
    e.preventDefault();
    $("#despliegaresultados, #paginacion").empty();
    $.post("php/prueba.php", $('#JqPostForm').serialize(), function (data) {
        $.each(data, function (i, item) {

            // NOTE: Ajax is async, the below values are only accessible
            //       after the ajax call has completed

            var total = item.total,
                datos = item.datos;
        });
    }, "json");
});

you forgot to mention

<form method="POST">
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top