开发者

after modify script, sEcho result not same

how to make the response result at sEcho become not zero?

{"sEcho": 0, 

i've been use this code but result still zero..

 $sOutput .= '"sEcho": '.intval($_POST['s开发者_如何学运维Echo']).', ';


Okay, time to elevate this to an answer.

 $sOutput .= '"sEcho": '.intval(postVar('sEcho')).', ';

This line takes the output of the function postVar, when given the paramater 'sEcho', then takes that result and runs it through the built-in function intval.

That integer is then appended using the . concatenation operator to the string '"sEcho":', which is then appended to the variable $sOutput

intval turns whatever it was passed into an integer. This is like casting. Pretty much any string is turned into zero. intval('YOUR FACE IS ON FIRE') will return 0, intval('') will return 0, etc.

I don't know where postVar is, but I'm going to wager based on the provided example code link that it's some ill-conceived wrapper around $_POST. So, another way to write it might be:

$sEcho = (int)$_POST['sEcho'];
$sOutput .= '"sEcho": ' . $sEcho . ', ';

The bottom line is that the thing being passed to intval is turned into zero. It's very likely that the input named "sEcho" is not a string that can be turned into anything but zero.

That's where your zero is coming from.

To fix it, you need to pass something to intval that won't get turned into a zero.


As a side-note, if you're actually using the linked example code, you should probably be aware that the code in question is complete, utter garbage. It's filled with bad practices, like persistent connections, the use of the outdated mysql extension, manual assembly of JSON strings, and the most horror of horrors, a poorly thought out Hungarian Notation style. Seriously, sEcho being a thing that was cast to an integer? Shouldn't it be iEcho then? Sigh.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜