0

I am building website under subdomain. Site path is following: www.sub.example.com/site

In that folder I have functions.php which I use to fire up php functions.

$.ajax({
  type: "POST",
  url: "http://sub.example.com/site/functions.php",
  data: { 
    action: 'sendData',
    data: exampleData
  },
  success: function(data){
    console.log(data);
  }
});

For reasons unknown Chrome's console return:

 POST http://sub.example.com/site/functions.php 500 (Internal Server Error)
 send        @    jquery-3.2.1.min.js:4
 ajax        @    jquery-3.2.1.min.js:4
 (anonymous) @    main.js:35
 dispatch    @    jquery-3.2.1.min.js:3
 q.handle    @    jquery-3.2.1.min.js:3

I have double checked that function file has no errors.

Php file: here

Jaakko Uusitalo
  • 655
  • 1
  • 8
  • 21

3 Answers3

0

Check your web server's error log this is mostly code error

B.Mossavari
  • 127
  • 6
0

you have an php error in file functions.php ... check server error log and try to allow to print php error form php.ini or put this code in the top of functions.php

error_reporting(E_ALL);
ini_set('display_errors', 1);
0

I finally fixed it. Reason was I used wrong sql syntax. I was trying to update row's cert value by inserting new one. What I needed to do is just update the existing one with new value.

What I had:

$addAmount = $conn->prepare("INSERT INTO data (certs) VALUES (:newAmount) WHERE place = :place");

What I needed:

$addAmount = $conn->prepare("UPDATE data SET certs = :newAmount WHERE place = :place");

Thanks everyone for helping.

Jaakko Uusitalo
  • 655
  • 1
  • 8
  • 21