2013-06-01 35 views
0

我正在創建一個小部件。我的jQuery的功能是:將值從Jquery加載到PHP頁面時傳遞值

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'。我也想將參數變量的值傳遞給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錯誤。有沒有人有任何線索爲什麼會發生這種情況。任何形式的積極建議表示讚賞。

在此先感謝....

+1

用參數替換參數 –

+0

@messifan感謝兄弟指出錯誤.... – V15HM4Y

+0

在更改Messi粉絲建議的內容後,錯誤仍然出現嗎?如果是的話,代碼中的哪一點? –

回答

1

您使用params(與-s後綴)作爲參數名稱,但嘗試在函數體引用它作爲param(沒有-s後綴)。你應該改變參數名稱爲param

相關問題