response body json raw errod data - Ajax wont accept json when array

I have the following line of code:
          print json_encode($organization_modules);
$organization_modules is an array that looks like this:
org_array
When i print this array to the following Ajax:
   $.ajax({
    type: 'POST',
    url: '/Module/findByCategory',
    dataType: 'json',
    data: {
        request: 'ajax',
        category_id: id
    },
    success: function (data) {
        $('#module_content').html('');
        $('#module_content').prepend('<div class="col-md-12"><a href="/Modules/index" class="btn btn-primary"><i class="fa fa-arrow-left"></i> Tilbage</a></div>');
        if(data.length > 0)
        {});
Nothing happens
However if i print the following instead:
working
it works just fine?
So does it have something to do with the null values or what is going on?
Response body
    <br />
<font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined offset: 0 in C:\xampp\htdocs\learning-bank\site\pages\models\Module.php on line <i>43</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0290</td><td bgcolor='#eeeeec' align='right'>141200</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\xampp\htdocs\learning-bank\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0930</td><td bgcolor='#eeeeec' align='right'>202464</td><td bgcolor='#eeeeec'>Framework\Core\Classes\PageRenderer->__construct(  )</td><td title='C:\xampp\htdocs\learning-bank\index.php' bgcolor='#eeeeec'>..\index.php<b>:</b>14</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0980</td><td bgcolor='#eeeeec' align='right'>254256</td><td bgcolor='#eeeeec'>Framework\Core\Classes\PageRenderer->executeAjax(  )</td><td title='C:\xampp\htdocs\learning-bank\core\classes\PageRenderer.php' bgcolor='#eeeeec'>..\PageRenderer.php<b>:</b>55</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.1010</td><td bgcolor='#eeeeec' align='right'>324752</td><td bgcolor='#eeeeec'>Module->findByCategory(  )</td><td title='C:\xampp\htdocs\learning-bank\core\classes\PageRenderer.php' bgcolor='#eeeeec'>..\PageRenderer.php<b>:</b>302</td></tr>
</table></font>
[{"id":"1","Category_id":"1","name":"Adf\u00e6rds styring","description":"Hello world","price":"200","mentor":null,"location":null,"start_date":null,"end_date":null,"time":null,"is_online":"1","status_id":"1","Material_id":null,"is_owned":"false"}]


Fixed it
I fixed it, apprently php was breaking because of undefined index
  •   You have an PHP errors in your response, try to switch off warnings in PHP. In the begginning of the file add:
    error_reporting( 0 );  
    ini_set( "display_errors", "0" );  
    
    And thet you can get valid json.
    Or try to fix this notice on 14 line in index.php.


Comments

Popular posts from this blog

Script For Login, Logout and View Using PHP, MySQL and Bootstrap

Real-Time Web Interface to MQTT using Socket.io and Node.js

Customize radio buttons and checkboxes with CSS sprites