2017-01-30 97 views
0

我想,當用戶使用搜索textbox更新我div內容與新的內容:jQuery的AJAX:未捕獲的SyntaxError:意外的標記

$('#business_request_filter_search_textbox').on('input propertychange paste', function() { 
    $.ajax({ 
     url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name"; 
     type: "GET", 
     cache: false, 
     data: { search: $('input#business_request_filter_search_textbox').val() }, 
     beforeSend: function(xhr) { 
      $('#request_area').html('<center>Please wait while we gather results...</center>'); 
     }, 
     success: function(data) { 
      $('#request_area').html(data); 
     }, 
    }); 
}); 

現在我有一個下拉列表中選擇他們想要來過濾搜索什麼通過,用戶名或企業名稱。這是拋出錯誤的線。

url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name"; 

我做錯了什麼?

+0

你檢查這個'$( 「#search_filter_selection」)[0] == .selectedIndex 1? 「get-requests-by-username」:「get-requests-by-business-name」條件? –

+0

may try($(「#search_filter_selection」)[0] .selectedIndex == 1)? 「get-requests-by-username」:括號中的「get-requests-by-business-name」 –

回答

1

你應該在url行的末尾逗號「」:

$('#business_request_filter_search_textbox').on('input propertychange paste', function() { 
    $.ajax({ 
     url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name", 
     type: "GET", 
     cache: false, 
     data: { search: $('input#business_request_filter_search_textbox').val() }, 
     beforeSend: function(xhr) { 
      $('#request_area').html('<center>Please wait while we gather results...</center>'); 
     }, 
     success: function(data) { 
      $('#request_area').html(data); 
     }, 
    }); 
}); 
0

您沒有爲ajax調用定義dataType。 添加的dataType這是您的Ajax請求的預期格式可以將文字,JSON等

0

試試這個代碼

$('#business_request_filter_search_textbox').on('input propertychange paste', function() { 
    $.ajax({ 
     url: "/ajax/housekeeping/business/" + $("#search_filter_selection")[0].selectedIndex == 1 ? "get-requests-by-username" : "get-requests-by-business-name", 
     type: "GET", 
     cache: false, 
     data: { search: $('input#business_request_filter_search_textbox').val() }, 
     beforeSend: function(xhr) { 
      $('#request_area').html('<center>Please wait while we gather results...</center>'); 
     }, 
     success: function(data) { 
      $('#request_area').html(data); 
     }, 
    }); 
}); 

希望這個幫到您:) :)享受

相關問題