My function transforms the parameter string to int.

I've a string variable in PHP, in php I call a test(variable) function, which is a jQuery function (in other file). When I show the variable in the function, get an int variable. Example:

File .php

$ids="304620,306408";
echo '<script>article('.$ids.');</script>';

File jQuery

function article(ids){
 alert(ids);  *//show 304620 only*
 alert(jQuery.type(ids)); *//show number*
}

Any idea?

有帮助吗?

解决方案

Quote your string while passing to function article()

$ids="304620,306408";
echo '<script>article("'.$ids.'");</script>';

其他提示

If you want to show 2 values in your jQuery function,Try passing an array from php into the jQuery function.

Secondly,By Default jQuery is changing the php's string value into a number datatype, So you could simply type cast your jQuery number variable into a string.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top