Al Capwner
Al Capwner

Reputation: 1

ajax post to php returns $_SERVER['REQUEST_METHOD'] GET

I'm trying to post newsletter form data to a php page with ajax but when I echo $_SERVER['REQUEST_METHOD'] on the php page it prints GET(with no variables). I have used similar code on multiple websites with no problems. (jquery v3.2.1)

  $.ajax({
            method: 'post', 
            dataType: 'json',
            url: '<?=$site_url?>/templates/xxxx/contact_send/email_send.php',
            data: JSON.stringify(dataString),
            contentType: 'application/JSON;charset=UTF-8',
            success: function () {
                console.log('success');
            }
        });

Network log

Network log

echo $_SERVER['REQUEST_METHOD'] echo $_SERVER['REQUEST_METHOD']

Response

Response

Upvotes: 0

Views: 1132

Answers (2)

Miro
Miro

Reputation: 8650

I would try to narrow down the problem by making a new HTML file with just your javascript code in it sending some fake data and a new PHP file with just echo $SERVER['REQUEST']; If it works you have some extra code that's messing it up. Otherwise it's some server issue. Did you make sure that you don't have .htaccess to forbid POST? Try adding this to the .htaccess Access-Control-Allow-Methods: POST, GET, OPTIONS

Upvotes: 0

Justin Tien
Justin Tien

Reputation: 67

browser of method is GET....(second image)

you should see network log image the response

Upvotes: 1

Related Questions