简体   繁体   中英

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??

Add this line to your head after jquery.js

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

Reference

.ajaxForm() is not a native jquery function. You have to include external js library to use .ajaxForm() . And important thing is .ajaxForm() will work with html form elements. I dont see form in your html code. If you want to use ajax call for your anchor just use .ajax() native function in your .mouseenter function:

Sample:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM