javascript - ajaxSetup beforeSend only being called the first time button is clicked -



javascript - ajaxSetup beforeSend only being called the first time button is clicked -

i using asp.net mvc , jquery 1.8.2

i have form button calls javascript when clicked:

$(function () { $('#searchbutton').click(function () { var info = $('#filterdefinition :input').serialize() + "&pagenumber=1"; $.post('@url.action("search")', data, loadcontentcallback); $("#searchresults").show(); }); });

this calls mvc controller action returns partialviewresult

on layout page have next javascript code:

//add custom header ajax requests $(document).ready(function () { $.ajaxsetup({ beforesend: function(xhr) { debugger; if ($('[name=__requestverificationtoken]').length) { var token = $('[name=__requestverificationtoken]').val(); xhr.setrequestheader('__requestverificationtoken', token); } } }); });

when button clicked first time, beforesend function called correctly. however, if button clicked more 1 time (for illustration alter search criteria , search again) beforesend function never gets called 1 time again , validate anti-forgery fails.

i tried using ajaxsend event instead , got same results.

any help solving problem appreciated.

thanks!

i avoid using $.ajaxsetup if possible. setup beforesend in actual post request.

javascript jquery asp.net ajax asp.net-mvc

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -