2011-08-30 89 views
0

我正在使用一個模塊並將格式設置從其他頁面複製過來,但似乎不起作用。是爲了從House Location中獲得價值,並在下面的框中創建頁面slu g。 Form類是粗糙的,我無法在Firebug中得到任何錯誤。Javascript ajax填充問題

控制器功能:

function stream_slug() 
{ 
    $this->load->helper('text'); 

    $this->output->set_output(url_title($this->input->post('location'), 'underscore', TRUE)); 
} 

HTML:

<label for="location">House Location:</label> <input type="text" name="location" value="" maxlength="250" /><span class="required-icon tooltip">Required</span></li> 

<li class="even"> 
<label for="slug">House Slug</label> 
<input type="text" name="slug" value="" maxlength="60" /><span class="required-icon tooltip">Required</span> 
</li> 

的jQuery:

(function($) { 
    $(function(){ 

     form = $('form.crud'); 

     $('input[name="location"]', form).keyup($.debounce(300, function(){ 

      slug = $('input[name="slug"]', form); 

      $.post(BASE_URI + 'index.php/admin/sales/stream_slug', { title : $(this).val() }, function(new_slug){ 
       slug.val(new_slug); 
      }); 
     })); 

    }); 
})(jQuery); 

更新的jQuery:

(function($) { 
    $(function(){ 

     form = $('form.crud'); 

     form.find('input[name="location"]', form).keyup($.debounce(function(){ 

      slug = $('input[name="slug"]', form); 

      $.ajax(BASE_URI + 'index.php/admin/sales/stream_slug', { title : $(this).val() }, function(new_slug){ 
       slug.val(new_slug); 
      }); 
     }, 300)); 

    }); 
})(jQuery); 

防抖動:

/* 
* jQuery throttle/debounce - v1.1 - 3/7/2010 
* http://benalman.com/projects/jquery-throttle-debounce-plugin/ 
* 
* Copyright (c) 2010 "Cowboy" Ben Alman 
* Dual licensed under the MIT and GPL licenses. 
* http://benalman.com/about/license/ 
*/ 
(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); 
+0

查看本示例,它使用jsfiddle的HTML回傳來模擬AJAX交互:http://jsfiddle.net/ambiguous/EgrJF/ –

+0

是否禁用/刪除dbounce文件?我仍然得到這個錯誤,我已經嘗試完整的文件 –

+0

比較你在做什麼和jsfiddle.net示例(哪些工作)。 –

回答

1

我的第一個猜測是,你有論據$.debounce向後:

$.debounce(fn, timeout, [invokeAsap], [ctx]); 

嘗試使用:

$('input[name="location"]', form).keyup($.debounce(function() { 
    //... 
}, 300)); 

我也建議您切換從

$('input[name="location"]', form) 

from.find('input[name="location"]') 

使得form沒有得到視覺上失去了右側,但是這僅僅是一個風格問題,主題到個人偏好(不同於外部API的參數順序)。

+0

仍然不工作奇怪 –

+0

@Jess:控制檯中的任何錯誤? PHP被調用了嗎?服務器日誌上的任何錯誤?你也有一個'

'HTML,對吧? –

+0

兩者都沒有錯誤,是表單類是crud –