Question: I'm pretty lost, all I want to do is spend a array to my javascript code. I've seen a lot of examples, but none ends me working. I need some help. I'm pretty stuck.

**functions.js**

```html
function cargaTemperatura(idsem){
    $.ajax({
        type: "POST",
        url: "load_temp.php",
        data: { idsem :  idsem },
        dataType: "json",
        success: function(data){
            alert(JSON.parse(data));
        },error: function(data){
            alert('error');
        }
    });
};
```

**load\_temp.php**

```html
<?php
include_once 'Includes/db.php';
$select = "SELECT * FROM CalTmp WHERE idsem='".$_POST['id_sem']."'";
$result = mysqli_query($link, $select) or die($select);
$array = mysqli_fetch_all($result,MYSQLI_ASSOC);
debug_to_console($result->num_rows);
debug_to_console($_POST['id_sem']);
echo json_encode($array);
```

Answer: 
My suggestion:   

**- Step 1:** In load\_temp.php. Hardcode idsem value. Check on browser. Make sure there has a json string   

**- Step 2:** Add this line

```
header("Content-type: application/json");

```

after

```
<?php

```
Solved!!

I've resolved through library MooTools. My final code is:

**Functions.js**

```js
function cargaTemperatura(idsem){
    var idsemJSON = JSON.encode(idsem);
    alert(idsemJSON);
    var miAjax = new Request({
        url: "carga_temp.php",
        data: "idsem=" + idsemJSON,
        onSuccess: function(data){
            alert(data);
        },
        onFailure: function(){
            $('resultado').set("html", "fallo en la conexion Ajax");
        }
    });
    miAjax.send();
};
```

**load\_temp.php**

```html
<?php
$misDatosJSON = json_decode($_POST["idsem"]);

include_once 'Includes/db.php';
$select = "SELECT * FROM CalTmp WHERE idsem='".$misDatosJSON."'";
$result = mysqli_query($link, $select) or die($select);
$array = mysqli_fetch_all($result);
debug_to_console($result->num_rows);
debug_to_console($_POST['id_sem']);
echo json_encode($array);
```

I hope someone will serve useful.
Certainly the mistake was in sending the variable that was not in JSON format.

Thanks,