Reputation: 1845
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>
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;
my result
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.
Upvotes: 2
Views: 204
Reputation: 1398
let's change this:
<?php
print $newclientprice;
print $status;
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;
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);
});
Upvotes: 1