jQuery loaded dialog AJAX 'done' catch echoed result

耗尽温柔 提交于 2019-12-12 03:49:24

问题


I have a page where I use load to load a dialog box. From that dialog box, I have jQuery in there that posts an ajax request to a PHP script. This all works fine. From the PHP I echo out the result and attempt to catch that on the done callback from this loaded dialog - but its not working. It updates the database, but I can't catch the echo. This works elsewhere in my site, but I can't get it working here. I think it might have something to do with the fact that this is coming from a 'loaded' dialog? Any help would be appreciated.

Code on original page initiating the load...

$('#edit_cats').click(function() {
   $('#overlay').show();
   $("#loader4").show().center();
   $('#dialogLoad').show().load('../../dialog/categories.php', {'site_user':'<?=$user_id?>','id':'<?=$blog['id']?>'});
});

AJAX code in the loaded dialog

$('.cat_input').bind('blur keyup', function(e) {
   if(e.type === 'keyup' && e.keyCode !== 10 && e.keyCode !== 13) return;
   $(this).hide();
   var cat_title = $(this).val();
   var cat_id = $('.cat_selected').attr('id');

   $.ajax({
      type: "POST",
      url: "../../system/process-cat-update.php",
      dataType: "json",
      data: { 'title':cat_title, 'cat_id':cat_id}
   }).done(function(data) {
      $('.cat_selected').find('.cat_title').html(data).show();
   });
});

PHP code

<?php 

include ('connect.php');
mysql_query("UPDATE blog SET category='".$_POST['title']."' WHERE id='".$_POST['cat_id']."' ");
echo $_POST['title'];

?>

回答1:


You aren't sending json in your response so dataType: "json" is incorrect, removing the dataType property should fix your problem. Also you aren't sanitizing you input so you are open to sql injection.



来源:https://stackoverflow.com/questions/14266414/jquery-loaded-dialog-ajax-done-catch-echoed-result

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!