Hi,
I have a trouble working with ajax function with yii, I have a cgridview and end column is an button update,
when I click button update, I want to call an ajax function to invoke controller action. But i’d try all week, but still not idea
This is my code in cbuttonColumn with the update button:
array(
'class' => 'CButtonColumn',
'header' => 'Actions',
'template' => '{update}',
'updateButtonUrl' => '"#"',
'updateButtonOptions' => array(
'class' => 'update',
),
),
I also have a javascript file included in page with jquery - ajax :
$('.update').click(function(){
var id = $(this).parent().parent().children(':nth-child(2)').text();
$.ajax({
url: '/QuanLyTour/congty/quickUpdate/',
type: "POST",
dataType: 'xml',
success: function(xml){
if($(xml).find("jobs")){
// alert($(xml).find("result").text());
alert("suuccess");
alert($(xml).find("job").text());
}
},
error: function(){
alert("error");
}
});
return false;
});
This is my controller action which named actionQuickUpdate():
public function actionQuickUpdate()
{
$value .= "<?xml version=\"1.0\"?>";
$value .= "<root><jobs><job>Done</job></jobs>";
$value .= "</root>";
echo $value;
}
When I click “update” button, it also alert error, that mean, the request fail, but when i tried without “dataType: xml”, the success option in ajax is called. So, i don’t understand what wrong with my code.
Hope you can solve this problem!