Error Jquery ajax method post but POST empty

0 votes

I have set method type as post but in Save.php I just get values either in $_GET or $_REQUEST but not in $_POST.

$.ajax({
    method: "post"
    , url: "save.php"
    , data: "id=453&action=test" 
    , beforeSend: function(){

    } 
    , complete: function(){ 
    }  
    , success: function(html){ 
        $("#mydiv").append(html);        
    }
});

My form looks like:

<form method="post" id="myform" action="save.php">

It was not working, looked around here and on Google, tried adding enctype

<form method="post" id="myform" action="save.php" enctype="application/x-www-form-urlencoded">

but still $_POST empty

How do I make it work?

Jun 16, 2020 in PHP by kartik
• 37,520 points
3,673 views

1 answer to this question.

0 votes

Hello @kartik,

Instead of method: "post" you need to use type: "POST"

So this should work without any alterations to your form HTML:

$.ajax({
    type: "POST"
    , url: "save.php"
    , data: "id=453&action=test" 
    , beforeSend: function(){

    } 
    , complete: function(){ 
    }  
    , success: function(html){ 
        $("#mydiv").append(html);        
    }
});

Hope this is helpful!!

Thank you!!

answered Jun 16, 2020 by Niroj
• 82,840 points

Related Questions In PHP

0 votes
0 answers

jQuery Ajax POST example with PHP

I want to send data from a ...READ MORE

Jul 25, 2022 in PHP by Kithuzzz
• 38,000 points
385 views
0 votes
1 answer

I am trying to run following command But I end up with an error :

Hello Nishant, You are getting this error because your ...READ MORE

answered Apr 9, 2020 in PHP by Niroj
• 82,840 points
801 views
0 votes
1 answer

Error:Jquery - Uncaught TypeError: Cannot use 'in' operator to search for '324' in

Hello @kartik, You have a JSON string, not ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
7,001 views
0 votes
1 answer

Error:uncaught exception: out of memory in Ajax Process

Hello @kartik, From your description of being redirected ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
1,944 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
4,599 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
3,284 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
1,323 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27, 2020 in PHP by Niroj
• 82,840 points
3,397 views
+1 vote
1 answer

Error:Ajax LARAVEL 419 POST error

Hello @kartik, Laravel 419 post error is usually ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
3,786 views
0 votes
1 answer

How to post the parameter in ajax call of jquery datatable?

Hello @kartik, Just pass it like a normal ...READ MORE

answered Jun 16, 2020 in PHP by Niroj
• 82,840 points
18,164 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP