当用户preSS按钮,数据将保存到database.After的成功,我想从数据库中检索数据,并将其放置在适当的TD(点击的TD的同一行中)我是成功检索数据,但不能检索到的数据分配给不同的TD
When the user press button the data will be save into database.After success I want to retrieve data from database and place it in the proper td ( in the same row of the clicked td) i am success to retrieve data but not assign the retrieved data to the different td
AJAX
$(document).ready(function(){
$('.edit2').on('click', function(){
arr = $(this).attr('class').split( " " );
var clientid=document.getElementById("client").value;
$.ajax({ type: "POST",
url:"clientnetworkpricelist/updateprice.php",
data: "value="+$('.ajax input').val()+"&rowid="+arr[2]+"&field="+arr[1]+"&clientid="+clientid,
success: function(data){
$('#CPH_GridView1_clientprice'+arr[2]).empty();
$('#CPH_GridView1_clientprice'+arr[2]).append(data);
$('.ajax').html($(this).val());
$('.ajax').removeClass('ajax');
}});
}
);
});
HTML
<td id="CPH_GridView1_clientprice'.$rows['net_id'].'" class="edit clientprice '.$rows["net_id"].'">'.$rows["clientprice"].'</td>
<td id="CPH_GridView1_Status'.$rows['net_id'].'" class="edit2 status '.$rows["net_id"].' "><img src="image/'.$rows["status"].'f.png" /></td>
在我updateprice.php我连接到数据库,并从数据库中获取价值的只是打印这样的检索值
in my updateprice.php i connect to database and retrieve value from the database any just print the retrieve value like this
print $newclientprice;
print $status;
我的结果。
在价值现在都出现在同一个TD,但我希望它在单独的TD 0/01在clientprice和增加状态
both the value are showing now in the same td but i want it in separate td 0/01 in clientprice and increase in status
Client Price status
0.01increase |
|
|
任何一个可以帮助我的感谢。
any one help me thanks.
让我们改变这一点:
<?php
print $newclientprice;
print $status;
我不知道你想做什么。由于您使用jQuery,让我们使用JSON,为我们的利益。 重要:以下$ C $,c取决于无输出执行之前被发送,和将立即完成PHP执行
I'm not sure what you're trying to do. Because you are using jQuery, let's make use of JSON for our benefit. Important: the following code depends on no output being sent before it executes, and it will finish the php execution immediately
<?php
// set type so client can understand what was sent
header('Content-Type: application/json');
// transform our 2 values into a JSON array,
// this will be transparently transformed into an array for your ajax handler
echo json_encode(array($newclientprice, $status));
// end the script, this is what the client ajax request wanted
exit;
我冒昧地重写code,使其看起来更清晰,并且至少有一些意见太
I took the liberty to rewrite your code so that it would seem clearer, and at least with a few comments too
$(document).ready(function(){
var onClick, ajaxSuccessHandleMaker;
onClick = function() {
var
url = 'clientnetworkpricelist/updateprice.php',
clientid = $('#client')[0].value,
classesArray = $(this).attr('class').split(" "),
// send data as object, jQuery will transparently transform for the server
data = {
value : $('.ajax input').val,
rowid : classesArray[2],
field : classesArray[1],
clientid : clientid
};
// send POST request and expect JSON
$.post(url,data,ajaxSuccessHandleMaker(classesArray),'json');
};
// success returns the ajax handler with a closure on classesArray
ajaxSuccessHandleMaker = function (arr) {
// the handler EXPECTS an array, which is why we have to protect output in updateprice.php
return function (arrayOf2vals) {
$('#CPH_GridView1_clientprice'+arr[2]).html(arrayOf2vals[0]);
$('#CPH_GridView1_Status'+arr[2]).html(arrayOf2vals[1]);
// I am not sure what you want with the following 2 lines of code
$('.ajax').html($(this).val());// what is this?
$('.ajax').removeClass('ajax');// what is this?
};
};
// set the onClick handler
$('.edit2').click(onClick);
});