0

I am sending data from jquery to php using ajax but the problem is that whenever i send Boolean data through jquery php recieved it as a string. but i want Boolean data as Boolean not as a string

this is the code

$.ajax({
    type: "POST",
    url: "updaterecord.php",
    data: { id:i, table:t, field:f, data: d },
    dataType: "json",
    success:function(s){
       alert("Saved Successfully ");
    },
    error:function(e){
       alert("Error ");
    }
});

now if i send true on php side i get true as a string not as a Boolean value.is there any way to send Boolean data as Boolean

user3681048
  • 113
  • 1
  • 1
  • 6
  • POST or GET HTTP request will always send text. You have to parse it on the other side. – Su4p Jun 04 '14 at 09:55
  • I dont think jquery ajax has functionality to specify the data type of the data being passed to remote server script. you can just send `true` or `false` in ajax call and compare the string at server script side to check whether its true value or false – dreamweiver Jun 04 '14 at 09:56
  • you can check in php if($_POST['YOUR_VARIABLE']=="true"){ //write code for true}else{//write code for false} – Nanhe Kumar Jun 04 '14 at 09:59
  • See answers in a similar question here: https://stackoverflow.com/questions/14716730/send-a-boolean-value-in-jquery-ajax-data – Phil Sturgeon Jun 04 '14 at 10:24

1 Answers1

0

Just send 1 or 0 (true or false) and don't bother with type casting.

h.s.o.b.s
  • 1,299
  • 9
  • 18