Ajax wont accept json when array

Marc Rasmussen

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

ostapische

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

JSON.parse() wont accept valid JSON

From Dev

TCP connection, serversocket.accept when running it wont create the socket

From Dev

PHP wont return anything to AJAX when adding certain Function

From Dev

Lua script wont accept args

From Dev

Why wont Shopify accept my theme's zip file when compressed using Powershell

From Dev

Why wont my Redux & React JSX accept my IF statement even when *outside* of my render?

From Dev

how to capture array in ajax page when sent through JSON object

From Dev

Ajax callback and variable scope when loading JSON file into array

From Dev

Accept JSON in Rails Controller when wrong format

From Dev

Cucumber wont accept Capybara Minitest Spec assertions

From Dev

Vim printoptions wont accept two options simultanenously

From Dev

Django test wont accept test user

From Dev

Expect json array in AJAX

From Dev

Javascript array : AJAX, JSON

From Dev

Flot wont upload JSON

From Dev

deferred for chaining ajax wont work

From Dev

AJAX wont apply value to variable

From Dev

jQuery Ajax Get wont work

From Dev

Form wont submit via ajax

From Dev

jQuery Ajax wont POST to php

From Dev

how to accept json array input in jersey Rest Webservice

From Dev

Get json array value with ajax

From Dev

How to parse json array with ajax?

From Dev

Returning a json array using AJAX

From Dev

Numpy: values in array wont change

From Dev

Array Wont Dump to Sheet? VBA

From Dev

mysql server wont accept id and datetime as a new record

From Dev

ASP.NET Web Api GET wont accept "." in URL Parameters

From Dev

UINavigationBar.appearance() wont accept UIColor defined by RGB or HUE