0

我正在创建一个小部件。我的jQuery函数是:

function init_widget(params){
    var protocol=window.location.protocol;
    var host=window.location.host;
    $("#wd_id").load(protocol+"//"+host+"/testfolder/index.php");
}

如上面的代码,我正在使用 jquery 加载'index.php'。我还想将param变量中的值传递给index.php. 我已经尝试过使用ajax,通过做类似的事情

function init_widget(params){
    var protocol=window.location.protocol;
    var host=window.location.host;
    $("#wd_id").load(protocol+"//"+host+"/cropimages/index.php");
    $.ajax({
        type: 'POST',
        url:index.php,
        data: param,
        success: function() {
            alert('asdf');    
        },
        error: function(){
            alert('failure');
        }
    });
}

但是,它显示错误为Uncaught ReferenceError: param is not defined。有谁知道为什么会这样。任何形式的积极建议表示赞赏。

提前致谢....

4

1 回答 1

1

您使用params(带 -s 后缀)作为参数名称,但尝试param在函数体中将其引用为(不带 -s 后缀)。您也应该将参数名称更改param为。

于 2013-06-01T10:17:29.450 回答