本文介绍了Javascript错误 - 未捕获的SyntaxError:意外的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome第3行的代码中收到'未捕获的SyntaxError:意外的标识符'

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);
        });
    }
}


推荐答案

你有一个语法错误,取决于你想要做什么这行应该是

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

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

或者如果你想将字符串'url'发送到get_bloginfo函数,你必须逃避单一引用

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.

以下行同样如此:

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

这篇关于Javascript错误 - 未捕获的SyntaxError:意外的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:04