开发者

jquery append on muliply array

开发者 https://www.devze.com 2023-01-09 13:56 出处:网络
this my code with in a array i supposed to make tree menu in a table $myqueryPO->magGrp = array(\"[grp] => MAIN, [grp] => P1,[grp] => P3\")

this my code with in a array i supposed to make tree menu in a table

$myqueryPO->magGrp = array("[grp] => MAIN, [grp] => P1,  [grp] => P3")
foreach ( $myqueryPO->magGrp as $dataArray) {
$myGroup = $dataArray[] = $dataArray['grp'];
    <tr class="'.$myGroup.'">
        <td><a href="#" id="'.$myGroup.'" class="clickMEdata">'.$myGroup.'</a></td>
        <td></td>
    </tr>

}


$(function($) {
$(".clickMEdata").click(function(){
var eleMent = $开发者_如何学JAVA(this);
var mySelected = eleMent.attr("id");
var info = "myID=" + mySelected;
$.ajax({
type: "POST",
url: "ScheduleOfManPower.php",
data: info,
success: function(data){    
var loadUrl = "ScheduleOfManPower.php";
 $("."+mySelected).append().load(loadUrl, info);
}
});
$("."+mySelected).toggle("slow");
});
}); 

supposed to be the ScheduleOfManPower.php is <tr><td>hi</td><td>foo</td></tr> my problem it seem my append function doesnt work my table not fit what i expected its only query in the 1st <td></td> my second problem is the $("."+mySelected).toggle("slow"); it seem i need to double click in order from me to show my query.. :(


I'm not sure from the question what's supposed to be going on, but you have a few issues off the bat. $("."+mySelected) is a .class selector, not an ID selector. You'll want this to search by ID:

 $("#"+mySelected)

But there's no need for that, just keep a reference, like this:

$(function($) {
  $(".clickMEdata").click(function(){
    var eleMent = $(this);
    $.ajax({
      type: "POST",
      url: "ScheduleOfManPower.php",
      data: { myID: eleMent.attr("id") },
      success: function(data){
        eleMent.closest('tr').after(data);
      }
    });
    eleMent.toggle("slow");
  });
});

This has a few other changes/fixes, you can pass data as an object making that cleaner. If you want to append the returned data you need to use data in your success function, calling .load() will fire another different AJAX request, which doesn't make much sense, but given you're loading it both ways, I'm not sure exactly what you're after...but I think the above is it.

There's one more big change, you were appending a <tr> inside an <a> which isn't valid at all, I changed it to insert it as the next row. This one I'm really unsure of, but it's the only thing close that's valid HTML, so please elaborate if it's not what you were after.


i get it ^^ .. thank u nick

$(function($) {
$(".clickMEdata").toggle(
function(){
var eleMent = $(this);
var mySelected = eleMent.attr("id");
var myHuraFrom = eleMent.attr("huraUna");
var myHuraTO = eleMent.attr("huraTwo");
var info = "myID=" + mySelected+ "&MaHuraFrom="+myHuraFrom+ "&myHuraTO="+myHuraTO;
$.ajax({
type: "POST",
url: "ScheduleOfManPower.php",
data: info,
success: function(data){        
eleMent.closest("tr").after(data);
}
});                                     
},
function (){
$(".activity").hide();  
});
});
0

精彩评论

暂无评论...
验证码 换一张
取 消