tags:

views:

58

answers:

2

now i made JavaScript code (jquery code) and when i click ok it return true if i want true and false if i want false

now the problem is php not consider true as php keyword true its just consider it a word like any other word and i must make it like this

if($post == 'true')

and i want make it like this

if($post) // retuen true if $post true

how i can do that and i use jquery function is() to send true or false to php

+5  A: 

Javascript can only send values to serverside PHP via POST or GET. The data is always of type string - even numbers, although PHP being a typeless language, the difference is hardly noticeable. You should return 0 or 1 and typecast it to bool if you really need it. One way to force a value to bool is boolVariable = !! variable;

Raveren
can you show by codes because i dont understand
moustafa
An alternative - you could return it as JSON using json_encode, I suppose, but that's a bit overkill.
Will Morgan
+1  A: 

Like Raveren said, you can't send integer, or boolean to PHP. All sent data is string, always. If you still want to use if ($post) and not if ($post == 'true') then use switch

switch($post)
{
    case "true":
        $post = true;
        break;
    case "false":
        $post = false;
        break;
}

if ($post) {
    ...
}

no other way to do it

Ergec