boolean variables posted through AJAX being treated as strings in server side

前端 未结 4 1705
南方客
南方客 2020-12-03 00:41

Following is a part of an AJAX functionality to add classes and packs to session cart:-

The jquery part

function addClassToCart(item         


        
4条回答
  •  青春惊慌失措
    2020-12-03 01:29

    Also you can use filter_var function with filter FILTER_VALIDATE_BOOLEAN. According to php documentation it

    Returns TRUE for "1", "true", "on" and "yes". Returns FALSE otherwise. If FILTER_NULL_ON_FAILURE is set, FALSE is returned only for "0", "false", "off", "no", and "", and NULL is returned for all non-boolean values.

    So receiving of POST parameter will look like:

    $isClass = filter_var ($_POST['isClass'], FILTER_VALIDATE_BOOLEAN);
    

提交回复
热议问题