iT邦幫忙

0

javascript function內參數 外部使用

請問因為在寫autocomplete 要呼叫jquery插件autocomplete
我想用javascript 呼叫一個function ,這個function會post資料給一個php程式檔,
然後接收這個php檔案回傳來的data 在這個function內處理 data的資料,
然後指派給變數。

最後在function印出這個資料
但是post function內指定的參數的資料 (傳值不傳址)
要怎麼用到外部可以繼續使用呢

var states = new Array();
	getlist();
	function getlist(){
		$.post('getparam.php', {
			'table': "customer",
	   },function(data){
	   	for(var i=0;i<data.length;i++)
	   	{
	   		states[i]= data[i].name;
            console.log("內部");
	   		console.log(states);   // <-這邊可以印出states

	   	}
		});

	}

	console.log("function後");
	console.log(states);    // <-這邊無法印出states
    
    $('#showMe').autocomplete({
	source:[states]

	}); 

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言