簡體   English   中英

如何在錨標記上執行Ajax調用

[英]How to perform ajax call on anchor tag

<script>
$(document).ready(function(){
  $('#test').mouseover(function(){
          $('#test').ajaxForm({ 
            beforeSubmit: ShowRequest,
            success: SubmitSuccesful,
            error: AjaxError                               
          });                                    
       });    
       }); 
        function ShowRequest(formData, jqForm, options) {

        $("#loading").show();
        return true;
        }

        function AjaxError() {
        }

        function SubmitSuccesful(responseText, statusText) {  
  $(function() {
  var array=['ravi','abhi','raj','amol','neha','snehal','skksldfjsfsdfddsf','dkfks'];
    // add loading image to div
  $(function() {
    $("#test").attr('title',array.join('<br/>'));
    $("#test").tooltip({

        content:function(){return $(this).attr('title');},

   position: {
        my: "center bottom-20",
        at: "center top",
        using: function( position, feedback ) {
          $( this ).css( position );
          $( "<div>" )
            .addClass( "arrow" )
            .addClass( feedback.vertical )
            .addClass( feedback.horizontal )
            .appendTo( this );
        }
      }
   });  
});
});

 }    
  </script>

<div id="loading"></div>

<p>Ravi, Raj and <a href="#" id="test" title="enable to load">5 more</a></p>

它顯示一個錯誤“未捕獲的TypeError:對象[object Object]沒有方法ajaxForm...。請告訴我應該進行哪些更改... ajax調用列表成功后應該顯示我的列表...”有什么辦法解決這個問題?

jquery.js之后將此行添加到您的頭部

<script src="http://malsup.github.com/jquery.form.js"></script> 

參考

.ajaxForm()不是本機jquery函數。 您必須包括外部js庫才能使用.ajaxForm() 重要的是.ajaxForm()將與html form元素一起使用。 我在您的html代碼中看不到表格。 如果要對錨使用ajax調用,只需在.mouseenter函數中使用.ajax()本機函數:

樣品:

$.ajax({
  url: "test.html",
  context: content
}).done(function() {
  // add code here to execute after ajax call
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM