简体   繁体   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>

it shows one error "Uncaught TypeError: Object [object Object] has no method ajaxForm.... Please tell me what changes should needed... on success of ajax call list should be my list should be display....... is there any way to solve this?? 它显示一个错误“未捕获的TypeError:对象[object Object]没有方法ajaxForm...。请告诉我应该进行哪些更改... ajax调用列表成功后应该显示我的列表...”有什么办法解决这个问题?

Add this line to your head after jquery.js jquery.js之后将此行添加到您的头部

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

Reference 参考

.ajaxForm() is not a native jquery function. .ajaxForm()不是本机jquery函数。 You have to include external js library to use .ajaxForm() . 您必须包括外部js库才能使用.ajaxForm() And important thing is .ajaxForm() will work with html form elements. 重要的是.ajaxForm()将与html form元素一起使用。 I dont see form in your html code. 我在您的html代码中看不到表格。 If you want to use ajax call for your anchor just use .ajax() native function in your .mouseenter function: 如果要对锚使用ajax调用,只需在.mouseenter函数中使用.ajax()本机函数:

Sample: 样品:

$.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