Ajax call is breaking Jquery toggle function

I have a basic toggle function, when item is clicked initially it sends an ajax post, and when clicked the second time it sends a second different ajax post. the issue is once it makes the ajax call, the second toggle function no longer fires. When I removed the ajax functions from the toggle and replaced them with a basic show/hide div, it worked just fine first and second click. Below is my code: You will notice I have a basic show/hide function for the first click, for testing purposes. Using this code the first click works, second click works and make the ajax call, but any clicks after dont do anything. //Sort by Instrument ACS or DESC $("th#seeking").toggle(function() { // first click update sorting order $("a.add_listing").hide(200); $("a.add_listing").show(200); }, function() { // On second Click toggle opposite sorting order $.ajax({ type: "POST", url: "ajax_calls.php", data: "order=instrument_asc&sort_item=true", success: function(r){$("#listings").html(r);}, error: function(){alert(2);$("#error").text("Could not retrieve posts").fadeIn(300).delay(900).fadeOut(300)} }) }); Any help on this would be very much appreciated. Many thanks
Do you get an error on the console?

以上就是Ajax call is breaking Jquery toggle function的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准