2015-09-27 81 views
-1

我有工作自動完成腳本,但它不能快速工作。因此我決定將我的數據轉移到另一個asp文件中。但是當我這樣做時,我遇到了問題。我的問題是如何將我的數據轉移到asp文件?我的工作示例代碼如下(這些不是我的數據,我從MSSQL中檢索數據並且至少有10000條記錄)。如何將jquery數據從主文件傳輸到asp文件?

<p> 
<input id="autocomplete2" type="text" placeholder="U.S. state name"> 
<input id="autocomplete2-value" type="text" name="code"> 
</p> 
<script> 
    var data = [ 
     { value: "AL", label: "Alabama" }, 
     { value: "AK", label: "Alaska" }, 
     { value: "AZ", label: "Arizona" }, 
     { value: "AR", label: "Arkansas" }, 
     { value: "CA", label: "California" }, 
     { value: "CO", label: "Colorado" }, 
     { value: "CT", label: "Connecticut" }, 
     { value: "DE", label: "Delaware" }, 
     { value: "FL", label: "Florida" }, 
     { value: "GA", label: "Georgia" }, 
     { value: "HI", label: "Hawaii" }, 
     { value: "ID", label: "Idaho" }, 
     { value: "IL", label: "Illinois" }, 
     { value: "IN", label: "Indiana" }, 
     { value: "IA", label: "Iowa" }, 
     { value: "KS", label: "Kansas" }, 
     { value: "KY", label: "Kentucky" }, 
     { value: "LA", label: "Louisiana" }, 
     { value: "ME", label: "Maine" }, 
     { value: "MD", label: "Maryland" }, 
     { value: "MA", label: "Massachusetts" }, 
     { value: "MI", label: "Michigan" }, 
     { value: "MN", label: "Minnesota" }, 
     { value: "MS", label: "Mississippi" }, 
     { value: "MO", label: "Missouri" }, 
     { value: "MT", label: "Montana" }, 
     { value: "NE", label: "Nebraska" }, 
     { value: "NV", label: "Nevada" }, 
     { value: "NH", label: "New Hampshire" }, 
     { value: "NJ", label: "New Jersey" }, 
     { value: "NM", label: "New Mexico" }, 
     { value: "NY", label: "New York" }, 
     { value: "NC", label: "North Carolina" }, 
     { value: "ND", label: "North Dakota" }, 
     { value: "OH", label: "Ohio" }, 
     { value: "OK", label: "Oklahoma" }, 
     { value: "OR", label: "Oregon" }, 
     { value: "PA", label: "Pennsylvania" }, 
     { value: "RI", label: "Rhode Island" }, 
     { value: "SC", label: "South Carolina" }, 
     { value: "SD", label: "South Dakota" }, 
     { value: "TN", label: "Tennessee" }, 
     { value: "TX", label: "Texas" }, 
     { value: "UT", label: "Utah" }, 
     { value: "VT", label: "Vermont" }, 
     { value: "VA", label: "Virginia" }, 
     { value: "WA", label: "Washington" }, 
     { value: "WV", label: "West Virginia" }, 
     { value: "WI", label: "Wisconsin" }, 
     { value: "WY", label: "Wyoming" } 
    ]; 
    $(function() { 
     $("#autocomplete2").autocomplete({ 
      source: data, 
      focus: function(event, ui) { 
       // prevent autocomplete from updating the textbox 
       event.preventDefault(); 
       // manually update the textbox 
       $(this).val(ui.item.label); 
      }, 
      select: function(event, ui) { 
       // prevent autocomplete from updating the textbox 
       event.preventDefault(); 
       // manually update the textbox and hidden field 
       $(this).val(ui.item.label); 
       $("#autocomplete2-value").val(ui.item.value); 
      } 
     }); 
    }); 
</script> 

感謝您的幫助...

+0

'我有一個problem'當我這樣做是不正確的問題說明。目前自動完成功能是如何工作的,爲什麼要將它移動到另一個文件上? – charlietfl

+0

它工作緩慢。它從另一個文件快速運行。我試過json,但腳本沒有接受asp文件中的json代碼。謝謝... – zokanzi

+0

沒有太多的解釋工作,並沒有回答問題 – charlietfl

回答

0

我發現我@charlietfl對問題的解決有所幫助。下面我的jquery代碼。

$(function() { 
    $("#Uni").autocomplete({ 
     source: "rm_universite2.asp", 
     minLength: 2 
}); 
}); 

而且rm_universite2.asp代碼:

If rsUrun.RecordCount > 0 Then 
i = 1 
Sinirla = 10 


output = "[" 

Do While Not rsUrun.EOF And i < (Sinirla + 1) 

output = output & "{""id"":""" & rsUrun("ID") & """,""value"":""" & rsUrun("Adi") & """}," 

i = i + 1 

rsUrun.MoveNext 
Loop 

output=Left(output,Len(output)-1) 
output = output & "]" 
End If 

Response.Write output 

這一切......

相關問題