Ajax XHR returns 500 error, but the PHP file works

Walker

New Member
#1
index.html (returns 500 error when running this ajax request)
Mã:
function checkUnread(username) {
  $.ajax( {
    type: "POST",
    url: "http://www.projecttranslation.org/cvlgbt/www/web/unreadcount.php",
    data: { user: username },
    cache: true,
    success: function ( data ) {
      alert(data);
    }
  })
}
unreadcount.php (works fine when run by itself)
Mã:
<?php

header('content-type: text/html; charset=utf-8');
header('Access-Control-Allow-Origin: *');

$link = new mysqli(BLOCKED FOR SECURITY REASONS);

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "1";

$result->close();

$link->close();
Obviously I removed some integral pieces of code for debugging and security purposes, but here is what I'm trying to do:

When the user logs in, I want checkUnread() to check the database for unread messages, count how many there are, and then return that number via the Ajax XHR. Once Ajax has the result, it then dynamically injects it into the bottom toolbar style jQuery Mobile menu to show an "Unread Count" such as "Mail [2]". If that makes sense...any thoughts why this would be returning a 500 error?
 

Admin

Administrator
Thành viên BQT
#2
I visited your link, but got status code 500 in console. And I notice that you use an undeined var $result in your code
Mã:
$result->close();
I doubt taht this code is the reason. If I am wrong, please check your error log configured in you php-fpm.conf and post it out
 
OP
OP
W

Walker

New Member
#3
I take that back, that was the problem, the variable I forgot to remove. Thanks for pointing out something so simple to me it wasn't obvious at all. I always miss the small things.
 

Từ khóa phổ biến

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top