0
votes

Here is my code:

$(document).ready(function(){
            $("#mainbutton").click(function(){
                $("#ajaxform").submit(function(e)
                {
                    $.ajax(
                    {
                        action : "mainbutton",
                        url : "userctrl",
                        type: "post",
                        data : $(this).serializeArray(),
                        success:function(data, textStatus, jqXHR) 
                        {
                            alert("success");
                        },
                        error: function(jqXHR, textStatus, errorThrown) 
                        {
                            alert("error"); 

                        }
                    });
                });
                $("#ajaxform").submit(); //Submit the form
            });
        });

I try to set action in this post request but when I try to get it from the servlet it is null. Tried to change the request to get and again null. Also tried to put content-type: application/x-www-form-urlencoded but again no success. How to put action in this request. And it is appropriate to put action in post? If not should i make hidden field instead ? Also how I can use the parameters in function(data, textStatus, jqXHR)

1
RTFM: api.jquery.com/jquery.ajax there is no action attribute in .ajax()Marc B

1 Answers

1
votes

There is no action attribute.

Instead, try changing your url attribute like this:

url : $("#ajaxform").attr('action')