How to get post values with ajax .post

I have two files filter.php and products.php included to index.php and I am using .post submit form without refreshing. I send data to products.php and return it back also i refresh my filter and there is my problem. When i try to var dump post data in filter.php it is empty

Here is my script

function ajaxFilter()
{
      var str = jQuery( "form[name=\"filters\"]" ).serialize();
      jQuery.post( "/", str )
            .done(function( data ) {
            var productList = jQuery(data).find(".list_product").html();
            var filter = jQuery(data).find(".filters").html();
            jQuery(".list_product").html(productList);
            jQuery(".filters").html(filter);
      });    
}

Any ideas how to get POST?

I though about putting my post via script to hidden inputs and return them also as html

If it is bad idea or just wrong start.

Answers


try this:

        var Data = $("form[name=\"filters\"]").serializeArray();  
        var URL = "products.php"; // whatever filepath where you send data
         jQuery.ajax({
            type: "POST",
            url: URL,
            processData: true,
            data: Data,
            dataType: "html",
            success: function (productList) {
                  // filter your result whatever you return from products.php  
                 jQuery(".list_product").html(productList);
            },
            error: function (x, y, z) {
                var a = x.responseText;
                jQuery(".list_product").html(a);
            }
        });

Use the full URL.

Provide the return values of .error() if you still have problems.


Need Your Help

Add string from TextSwitcher to array

android arrays string

I want to put the currently displayed string from TextSwitcher (string is placed in one's string array) to other string array and I don't know which method should I do because .getText doesn`t work...

NUnit with Windows Phone 7

nunit windows-phone-7 unitdriven

I'd like to unit test my Windows Phone 7 libraries with NUnit.