admin管理员组

文章数量:1317365

I am getting a 'Uncaught SyntaxError: Unexpected identifier' on the code below on line 3 in Chrome

function popup_shortlist(sel_id){
    var paramdata=Array();  
    paramdata[0]='<?php echo get_bloginfo('url'); ?>';
    paramdata[1]= $('#'+sel_id).val();

    var to_shortlist=false;
    var url='<?php echo bloginfo('url'); ?>/wp-admin/admin-ajax.php';

    if($('#'+sel_id).attr('checked')){
        $("#alert_titleid").empty().html('Adding to Shortlist');
        $("#alert_msgid").empty().html('loading...');
        display_alert();  
        var rqpage='add to shortlist';  

        var arr_dataval = {
            action: 'instinct_controller',
            rqpage:rqpage,paramdata:paramdata
        };

        $.post(ajaxurl,arr_dataval ,function(data){
            $("#alert_msgid").empty().html(data);
        });

    }else{
        $("#alert_titleid").empty().html('Removing from Shortlist');
        $("#alert_msgid").empty().html('loading...');
        display_alert();  
        var rqpage='remove from shortlist';
        var arr_dataval = {
            action: 'instinct_controller',
            rqpage:rqpage,
            paramdata:paramdata
        };
        $.post(ajaxurl,arr_dataval ,function(data){
            $("#alert_msgid").empty().html(data);
        });                 
    }   
}

I am getting a 'Uncaught SyntaxError: Unexpected identifier' on the code below on line 3 in Chrome

function popup_shortlist(sel_id){
    var paramdata=Array();  
    paramdata[0]='<?php echo get_bloginfo('url'); ?>';
    paramdata[1]= $('#'+sel_id).val();

    var to_shortlist=false;
    var url='<?php echo bloginfo('url'); ?>/wp-admin/admin-ajax.php';

    if($('#'+sel_id).attr('checked')){
        $("#alert_titleid").empty().html('Adding to Shortlist');
        $("#alert_msgid").empty().html('loading...');
        display_alert();  
        var rqpage='add to shortlist';  

        var arr_dataval = {
            action: 'instinct_controller',
            rqpage:rqpage,paramdata:paramdata
        };

        $.post(ajaxurl,arr_dataval ,function(data){
            $("#alert_msgid").empty().html(data);
        });

    }else{
        $("#alert_titleid").empty().html('Removing from Shortlist');
        $("#alert_msgid").empty().html('loading...');
        display_alert();  
        var rqpage='remove from shortlist';
        var arr_dataval = {
            action: 'instinct_controller',
            rqpage:rqpage,
            paramdata:paramdata
        };
        $.post(ajaxurl,arr_dataval ,function(data){
            $("#alert_msgid").empty().html(data);
        });                 
    }   
}
Share Improve this question edited Dec 22, 2013 at 2:41 Qantas 94 Heavy 16k31 gold badges72 silver badges88 bronze badges asked Dec 22, 2013 at 1:29 neilgeeneilgee 5381 gold badge6 silver badges18 bronze badges 1
  • Double quotes vs single quotes, see the syntax highlighting? – elclanrs Commented Dec 22, 2013 at 1:34
Add a ment  | 

2 Answers 2

Reset to default 2

You have a syntax error, depending on what you want to do this line should be

paramdata[0]='<?php echo get_bloginfo(' + url + '); ?>';

or if you want to send the string 'url' to the get_bloginfo function you have to escape the single quotes

paramdata[0]='<?php echo get_bloginfo(\'url\'); ?>';

my guess is that you want to do the first one.

Same thing in the following line:

var url='<?php echo bloginfo(' + url + '); ?>/wp-admin/admin-ajax.php';

Looks like you want paramdata[0] to be a straight string, no concatenation involved? In that case, use double quotes on the outside, or it treats the single quotes around 'url' as ending a string and looks for a + or a ;.

function popup_shortlist(sel_id){
    var paramdata=Array();  
        paramdata[0]="<?php echo get_bloginfo('url'); ?>";

本文标签: jqueryJavascript ErrorUncaught SyntaxError Unexpected identifierStack Overflow