ajax to php (POST)

ajax to php (POST)

hey guys im trying to post data to php via ajax...now ive tested the script and it seems like the problem is the data being sent...casue if i return json data without relying on data being sent from the ajax request then it works perfect.

so my question is how do i sent the data correctly so i can get it in my $_POST variable.

  1. $.ajax({
                dataType: "json",
                type: "POST",
                data: "{'category': '" + category + "'}", // problem
                url: "http://url.com/category/sub-categories",
                success: function(data) {
                   
                    $('#sub_category').empty();
                   
                    $.each(data, function(key, value) {  
                        $('#sub_category')
                        .append($("<option></option>")
                        .attr("value", value)
                        .text(key));
                    });
                   
                    $('#sub_category').show();
                },
                error: function(data) {
                    alert('error');
                }
            });
thank you guys