开发者

string parameter cannot be passed

i.m kind of confuse about this code

if($filter_col!=null && $filter_val!=null)
        $filter = $filter_col."|".$filter_val;      
        $prevpage = $current_page-1;
        printf('<ul class="pagination" style="float:right;">');
    if ( $current_page > 1 ) {       
        echo "<li><a href='#' onclick='loadPage(1,$filter)'>First</a> \n </li>";
        echo "<li><a href='#' onclick='loadPage($prevpage,$filter)'>Prev</a> \n </li>";
    }


function loadPage(page,filter){var dataString;  

dataString = 'page='+ page+'&filter='+filter;  $.ajax({
url: "page_data.php", //file tempat pemrosesan permintaan (request)
type: "GET",
data: dataString,
    success:function(data)
    {
        $('#divPageData').html(data);
    }});}

when i fill the $filter with any string as well as empty string for example 'oke' then it has an error said oke is not defined, but when i fill $filter fit any n开发者_如何学JAVAumber it works well can anyone help me? thanks in advance...


When you fill in a php var like $filter, then insert it verbatim into Javascript, you have to make sure that it becomes valid javascript. e.g:

$filter = 'oke';
$prevpage = 1;

... onclick='loadPage($prevpage,$filter)' ...

will become

... onclick='loadPage(1,oke)' ...

which is not valid Javascript, as there is no variable named 'oke' in your script. You have to do one of the following:

$filter = json_encode('oke');
$prevpage = json_encode(1);

which turns your PHP variable values into native javascript values, or at bare minimum surround the variables with quotes in the javascript part of your code:

... onclick='loadPage(\'$prevpage\', \'$filter\')' ...
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜