2016-07-28 1 views
0

応答が空のときに「結果が見つかりません」というメッセージを表示したい場合があります。その時にバックエンドセッションが期限切れになると、 jsonデータが必要なので、どのようにこのhtmlデータを処理できます。

$("#customers_name") 
    .bind("keydown", function(event) { 
    if (event.keyCode === $.ui.keyCode.TAB && 
     $(this).autocomplete("instance").menu.active) { 
     event.preventDefault(); 
    } 
    }) 
    .autocomplete({ 
    source: function(request, response) { 
     $.getJSON("ajax_functions.php", { 
     term: extractLast(request.term), 
     console: $('select[name="console"] option:selected').val(), 
     call: 'getCustomersEmailList', 
     nmsAdmin: '<?php echo tep_session_id();?>' 
     }, response); 
    }, 
    change: function (event, ui) { 
     if(!ui.item){ 
      $("#customers_name").val(""); 
     } 
    }, 
    focus: function() { 

     return false; 
    }, 
    select: function(event, ui) { 
     var customer_id = ui.item.customer_id; 
     var customer_email = ui.item.customerEmail; 
     console.log(ui); 
     $('#customer_id').val(customer_id); 
     $('#customer_email').val(customer_email); 
     var terms = split(this.value); 

     terms.pop(); 

     terms.push(ui.item.value); 

     terms.push(""); 
     this.value = terms.join(""); 
     return false; 
    } 
}); 
+0

これはどういう意味ですか? http://stackoverflow.com/a/4719848/961526 –

+0

@RaphaëlAlthaus:ええ、これは1つの質問でしたが、そのときに応答がHTMLデータを返すときはどうすればいいですか... – codever

+0

これをもっとグローバルに管理することができます:http ://stackoverflow.com/questions/12703942/handling-session-time-out-when-ajax-call-to-c-sharp-mvc-controller-not-workingまたはhttp://stackoverflow.com/questions/5238854/handling-session-time-in-ajax-calls –

答えて

3

私はあなたのコードを編集して、うまく動作します。下のコードを確認してください。

$("#customers_name") 
    .bind("keydown", function(event) { 
    if (event.keyCode === $.ui.keyCode.TAB && 
     $(this).autocomplete("instance").menu.active) { 
     event.preventDefault(); 
    } 
    }) 
    .autocomplete({ 
    source: function(request, response) { 
     $.getJSON("ajax_functions.php", { 
     term: extractLast(request.term), 
     console: $('select[name="console"] option:selected').val(), 
     call: 'getCustomersEmailList', 
     nmsAdmin: '<?php echo tep_session_id();?>', 
     dataType:'json', 
     },response).fail(function(jqXHR, status, error){ document.location.href='login.php'; }); 
    }, 
    response: function(event, ui) { 
     console.log(ui.content); 
     if (ui.content.length === 0) { 
      alert("No results found"); 
     } 
    }, 
    change: function (event, ui) { 
     if(!ui.item){ 
      $("#customers_name").val(""); 
     } 
    }, 
    focus: function() { 

     return false; 
    }, 
    select: function(event, ui) { 
     var customer_id = ui.item.customer_id; 
     var customer_email = ui.item.customerEmail; 
     console.log(ui); 
     $('#customer_id').val(customer_id); 
     $('#customer_email').val(customer_email); 
     var terms = split(this.value); 

     terms.pop(); 

     terms.push(ui.item.value); 

     terms.push(""); 
     this.value = terms.join(""); 
     return false; 
    }, 
    error : function() { document.location.href='login.php';} 
}); 
関連する問題