如何使用两个$ .post方法 [英] how to use two $.post methods very well

查看:128
本文介绍了如何使用两个$ .post方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 function ChangeGallery(){
    var GalleryName = $('.SubSubGalleryLock').text();

    /*Send string to Data1.php and include Tags from Database*/
    $.post("Data1.php", {  Sections: GalleryName  },
    function(data){
         $(".IncludeData").append(data);
    }); 

    /*send string to Data2.php and include Events data from Database*/
    $.post("Data2.php",{  GallerySec: GalleryName  },
    function(response){
         /*when i use alert method, this function works very well, why?*/
         alert('SomeString');
     var data = jQuery.parseJSON(response);
         var ImageID  = data[0];
         var ImageSrc = data[1];
     $(ImageID).click(function(){
        $(".LargeImage").attr('src', ImageSrc);
     });
     });
};

在Data1.php中

in Data1.php

  /*give data from database1 and print to HTML File*/
  if ($_POST['Sections']) == "String")
  {  $results = mysql_query("SELECT * FROM Table1");
  while($row = mysql_fetch_array($results))
  { echo $row['Tags']; }



in Data2.php

  /*give data from database2 and Use for events*/
  if ($_POST['GallerySec']) == "String")
  {  $results = mysql_query("SELECT * FROM Table2");
  while($row = mysql_fetch_array($results))
  { echo json_encode($row); }

然后Data1.php工作得非常好,但Data2.php只在我写了一个警报('Some stringh'); var data = jQuery.parseJSON(response);行,它工作得很好,为什么?是什么导致了这个问题?你可以​​在这个页面上看到它 http://www.3dcreate。 ir / Pages / Gallery / GalleryShow.php

in Client side when i use it then Data1.php works very well but Data2.php only when i write an alert('Some stringh'); after var data = jQuery.parseJSON(response); line, it's work well, why? what's due to this problem?you can see it in this page http://www.3dcreate.ir/Pages/Gallery/GalleryShow.php

推荐答案

jQuery不会绑定到添加到DOM的新元素被调用之后,除非你在被添加后重新绑定或者最初绑定到父元素:

jQuery won't bind to new elements added to the DOM after being called unless you rebind after they've been added or you bind to the parent element initially:

$("#Chosen_Div-parent").on("mouseover", ".Chosen_Div", function(event){
  //Some codes
});

(如果你有多个 Chosen_Div 元素,使用类来代替id)

(If you're ever going to have more than one Chosen_Div element, use classes instead of ids)

阅读 docs

这篇关于如何使用两个$ .post方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆