Newbie Spellweaver
- Joined
- May 23, 2014
- Messages
- 63
- Reaction score
- 10
Basically, the idea is I want the AJAX to run the lovedj script (below) and then return the encoded JSON information, to put into a notification box. However I seem to be getting the error 'Uncaught TypeError: Cannot read property 'msg' of null'
jQuery Script:
LoveDJ script:
JSON (var_dump of the script):
jQuery Script:
Code:
_buildLove: function() { $.ajax({
type: 'POST',
url: "web-structure/inc/radio/lovedj.php",
type: "POST",
dateType: "json",
success: function(data) {
alert(data.msg);
}
});
},
LoveDJ script:
PHP:
<?php
require_once '../../../staff/_inc/glob.php';
$query = $db->query( "SELECT * FROM connection_info ORDER BY id DESC LIMIT 1" );
$array = $db->assoc( $query );
$stats = $core->radioInfo( "http://{$array['host']}:{$array['port']}" );
$usercount = $db->query("SELECT * FROM users WHERE username = '".$stats['streamtitle']."'");
$growl = array();
if ($db->num($usercount) == 0) {
$growl['title'] = "This user is not in our database";
$growl['msg'] = "Sadly, this user is not in our database, we will look into this asap.";
$growl['error'] = true;
}
else {
$query2 = $db->query("UPDATE users SET likes = likes + 1 WHERE username = '".$stats['streamtitle']."'");
$growl['title'] = "";
$growl['msg'] = "";
$growl['error'] = false;
}
header("Content-Type: application/json", true);
json_encode($growl);
?>
JSON (var_dump of the script):
Code:
[COLOR=#00008B]string[/COLOR][COLOR=#000000]([/COLOR][COLOR=#800000]135[/COLOR][COLOR=#000000])[/COLOR][COLOR=#800000]"{"[/COLOR][COLOR=#000000]title[/COLOR][COLOR=#800000]":"[/COLOR][COLOR=#2B91AF]This[/COLOR][COLOR=#000000] user [/COLOR][COLOR=#00008B]is [/COLOR][COLOR=#00008B]not [/COLOR][COLOR=#00008B]in [/COLOR][COLOR=#00008B]our[/COLOR][COLOR=#000000] database[/COLOR][COLOR=#800000]","[/COLOR][COLOR=#000000]msg[/COLOR][COLOR=#800000]":"[/COLOR][COLOR=#2B91AF]Sadly[/COLOR][COLOR=#000000],[/COLOR][COLOR=#00008B]this[/COLOR][COLOR=#000000] user [/COLOR][COLOR=#00008B]is [/COLOR][COLOR=#00008B]not [/COLOR][COLOR=#00008B]in [/COLOR][COLOR=#00008B]our[/COLOR][COLOR=#000000] database[/COLOR][COLOR=#000000],[/COLOR][COLOR=#000000] we will look [/COLOR][COLOR=#00008B]in to [/COLOR][COLOR=#00008B]this[/COLOR][COLOR=#000000] asap[/COLOR][COLOR=#000000].[/COLOR][COLOR=#800000]","[/COLOR][COLOR=#000000]error[/COLOR][COLOR=#800000]":true}"[/COLOR]