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

4
  • POST or GET HTTP request will always send text. You have to parse it on the other side. Commented Jun 4, 2014 at 9: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 Commented Jun 4, 2014 at 9:56
  • you can check in php if($_POST['YOUR_VARIABLE']=="true"){ //write code for true}else{//write code for false} Commented Jun 4, 2014 at 9:59
  • See answers in a similar question here: stackoverflow.com/questions/14716730/… Commented Jun 4, 2014 at 10:24

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.