0

Im sending some data with ajax to a php function which uses the data to get an array containing numbers from the database. I need to get this array to my javascript part to activate some checkboxes with it.

My ajax function:

function ajax2(info){
        $.ajax({
            type:"POST",
            url:"publikationen2.php",
            data: {output2: info},  
            dataType: 'json',               
            success: function(data){
                alert(data);
            },
            error:  function(data){ 
                alert(data);    
            }
        });
    };

the end of the PHP part:

echo json_encode($IDarray); 

The problem is, the alert is only triggering in the error call of the ajax. And it shows me:

[object Object]
Benny Müller
  • 185
  • 1
  • 14
  • 2
    This is normal behaviour and also the reason why you shouldn't use `alert()` for debugging - as it coerces objects to strings. Given that you're seeing `[object Object]` it means the request is working and data is being returned, you just need to use `console.log(data)` to see it. – Rory McCrossan Jan 06 '16 at 14:18
  • To add to @RoryMcCrossan comment [Quit using `alert()` for troubleshooting.](http://stravid.com/en/stop-the-javascript-alert-madness/), use `console.log()` instead. – Jay Blanchard Jan 06 '16 at 14:19
  • Alredy tried it, but how can i use it to get my array, cause there are way tio much information and im not seeing the numbers im seraching for ? – Benny Müller Jan 06 '16 at 14:22
  • You would be best to start a new question for that, including the JSON data you're retrieving and also stating what you're trying to get out of it, and what you've tried so far. – Rory McCrossan Jan 06 '16 at 14:24

0 Answers0