Bonjour à tous,
Je fatigue la. Le script php retourne un json valide, mais Firebug me permet de voir qu'il y a des caractère inconnu (??????????????) à la fin de la chaine json lorsqu'elle retouné à la fonction ajax.
Script php:
Code :
1 2 3 4 5 6 7 8
|
//header("Content-Type: application/json");
$data = DB::typeAlerte()->all();
for($i=0;$i<sizeof($data);$i++)
$rep[] = $data[$i]['id'];
echo json_encode($rep); |
Script js:
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
myJ.ajax({
type: 'POST',
url: '../lib/form/f_idTypeAlerte.php',
dataType:'json',
success: function(msg) {
var selectedVal;
if( type == 'edit' )
selectedVal = table.fnGetData(selectedRow)[2];
formTools.clearSelect(idFieldType);
formTools.populateSelect(idFieldType, msg, true,
selectedVal);
},
error: function(xhr,status,error) {
alert(xhr.responseText+'|'+status+'|'+error)
}
}); |
Firebug :
Code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
##header
#response
HTTP/1.1 200 OK
Date: Tue, 03 May 2011 14:47:51 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Length: 644
Keep-Alive: timeout=5, max=98
Connection: Keep-Alive
Content-Type: application/json
#request
POST /parcVehicule/lib/form/f_idTypeAlerte.php HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://localhost/parcVehicule/web/index.php?page=voitures
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 0
## Response
["COURROIE","PNEUS ARRIERE","PNEUS AVANT","VIDANGE"]��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������� |
Impossible de savoir d'ou viennent tous ces caractères
EDIT : Histoire d'avoir l'air bien bète. Ces fameux caractères... Ce sont des espaces aprés la fermeture php "?>". Je me demande toujours comment 300 espaces ont pu arriver la T_T
Vous pouvez rire, vous avez le droit..