2011-07-17 54 views
0

我正在嘗試做一個ajax請求。 現在,當我點擊表單中的選項時,沒有發出Ajax請求。但是我去了正確的頁面。jquery幫助製作ajax請求

我的Jquery:

$(document).ready(function() { 
    // send form ved klik paa listen 
    $('option').click(function() 
    { 
     var form=$(this).closest('form'); 
     $.ajax({ 
      type:'post', 
      url:form.attr('action'), 
      data:form.serialize(), 
      success:function(msg){ 
      $('#formcontent').html(msg); 
      } 
     }); 
    }); 
}); 

$().ready(function() { 
    $('#jump_nav_submit').hide(); 
}); 

$('#jump_nav').live('change', function() { 
    window.location = "\/finder\/" + $(this).val(); 
}); 

我如何做Ajax請求,從而使得與ID formcontent div和URL是取景器/ whateverthevalueofthe選項。

我試圖刪除此:

$().ready(function() { 
    $('#jump_nav_submit').hide(); 
}); 

$('#jump_nav').live('change', function() { 
    window.location = "\/finder\/" + $(this).val(); 
}); 

但是Ajax請求不能正常工作,因爲該參數是: http://localhost:3000/finder/?id=16&utf8=%E2%9C%93

相反的:http://localhost:3000/finder/1

回答

1

選項元素不支持點擊事件跨瀏覽器。它在Fifrefox中有效,但不能在ie中記住關於chrome/safari。

無論支持所有瀏覽器,您都必須在select change事件中執行ajax調用。

你的代碼片段並沒有讓你明白你想要實現的選項,然後點擊選擇改變事件的重定向,所以很難進一步提供建議。

+0

我想動作網址爲:「\/finder \ /」+ $(this).val(); 而不是form.attr('action')。當用戶點擊一個選項時,requestet頁面應該在formcontent div中呈現,並且ajax url應該是/ finder /選項的值 –