2013-02-11 116 views
1

我正在使用jQuery方法開發Country,State,City,但是問題是當load事件觸發,也改變()被觸發,並且我無法加載狀態下拉關於加載事件,選擇更改事件觸發,jQuery

$("#SelectCountry").load() { 
    $.ajax({ 
     url: "../Member/Home.aspx/GetCountryName", 
     type: "POST", 
     dataType: 'json', 
     contentType: 'application/json; charset=utf-8', 
     data: "{'name': '" + "1" + "'}", 
     async: false, 
     success: function (response) { 
      if (response.d != null) { 
       $.each(response.d, function (i, response) { 
        debugger; 
        $("#SelectCountry").append("<option value=" + response.CountryId + ">" + response.CountryName + "</option>"); 
       }); 
      } 
     }, 
     error: function (xhr) {} 
    }); 
} 
$("#SelectCountry").change() { 
    alert("Select event changed;"); 
} 
+0

如果你的代碼格式正確,好的東西就會發生在你身上! :) – Trufa 2013-02-11 16:07:40

回答

1

你應該

$("#SelectCountry").load(function() { // pass a callback to load 
    ... // will be executed when loading finishes 
}); 

但在更換

$("#SelectCountry").load() { // doesn't compile 
    ... 
} 

你的情況,即使我沒有看到HTML,我不明白你爲什麼要使用加載。你應該簡單地調用塊內的代碼。

+0

你的小提琴不導入jquery,並沒有html ... – 2013-02-11 16:35:32

+0

我只是想顯示一個腳本!,我打算髮布在pastebin上,謝謝你的回覆 – 2013-02-11 16:39:50

+0

好的,寫這個我能夠激發我的webmethod :http://pastebin.com/CpFDQQwF – 2013-02-11 16:41:18