Javascript Error - Uncaught SyntaxError: Unexpected identifier

27,784

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';
Share:
27,784
neilgee
Author by

neilgee

Updated on July 09, 2022

Comments

  • neilgee
    neilgee almost 2 years

    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);
            });                 
        }   
    }
    
  • cssyphus
    cssyphus over 8 years
    Actually, that is PHP, so it should be . instead of + : paramdata[0]='<?php echo get_bloginfo(' . $url . '); ?>';, yes?