1

I have a div and when click it ,it goes to fetch some information from server and put themes to itself content to show it to user it works fine but I do not know how to handle it ,when user clicked on other part of page cancel this event that fired?

 <div id="picdiv" onmouseover="getit(this,'123')"></div>

my function:

function getit(picdiv, pid) {

  $('#picdiv').html('please wait...');

 $.ajax({
    url: "/Getcontent",
    type: 'POST',
    dataType: 'json',
    data: null,
    contentType: 'application/json; charset=utf-8',
    success: function (content) {
        $('#picdiv').html(content);

    },
    error: function (content) {
       //do something
    }
   });
}
5
  • You can't cancel an event that has already been handled. Do you mean you want to cancel the AJAX request that's in progress?
    – Barmar
    Commented Jul 30, 2013 at 3:29
  • @Barmar exactly i want to cancel the AJAX request that's in progress
    – Davood
    Commented Jul 30, 2013 at 3:30
  • I found that question by putting "cancel ajax request" into the SO search box.
    – Barmar
    Commented Jul 30, 2013 at 3:30
  • @motevallizadeh other part of the page means? a simple ajax.abort() will solve the problem I guess so.
    – Praveen
    Commented Jul 30, 2013 at 3:41
  • when user hold mouse on div and when my function done working it start to works again like a loop how to handle this?
    – Davood
    Commented Jul 30, 2013 at 3:49

0

Browse other questions tagged or ask your own question.