Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
372 views
in Technique[技术] by (71.8m points)

jquery - how to use two $.post methods very well

 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);
     });
     });
};

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); }

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're trying to access to the element as by class name, you should do it by id:

$('#Chosen_DIV').mouseover(function() {
    //SomeCodes
})
$('#Chosen_DIV').mouseout(function() {
    //SomeCodes
})

this should work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...