2

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);
        });                 
    }   
}
1
  • Double quotes vs single quotes, see the syntax highlighting? Commented Dec 22, 2013 at 1:34

2 Answers 2

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';
Sign up to request clarification or add additional context in comments.

1 Comment

Actually, that is PHP, so it should be . instead of + : paramdata[0]='<?php echo get_bloginfo(' . $url . '); ?>';, yes?
0

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'); ?>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.