문제

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