mardi 14 juin 2016

send post data from js to php using ajax without type cast


I have object in javascript and I need send this object to php using ajax.

I can "just send" this object, but my problem is that I need send object value types exactly as they are and not everything as string: meaning NULL as NULL, boolean values as boolean and so on...

Trying this:

var js_object= <?php echo json_encode( array("a"=>NULL, "b"=>TRUE, "C"=>1.1) ); ?>;

$.ajax({
    type: "POST",
    url: "some.php",        
    dataType: "json",
    data: JSON.stringify(js_object),
    contentType: "application/json; charset=UTF-8",
    success: function(msg){
    }
});

but this does not sends data to server at all. and not gives any error also. where I am wrong ?


Aucun commentaire:

Enregistrer un commentaire