h3rm
1
hello 
i have problem about jquery, this my code not use Yii
function loadData(){
$.ajax({
type:"POST",
url: "proses.php",
data: "act=show",
success:
function (data){
list.html(data);
}
});
}
i tried this:
<?php
Yii::app()->clientScript->registerScript('show', "
function loadData(){
$.ajax({
type:"POST",
url: "proses.php",
data: "act=show",
success:
function (data){
list.html(data);
}
});
}
");
?>
how to run this code with Yii ?
thank you
migajek
(Migajek)
2
<?php
Yii::app()->clientScript->registerScript('show', "
function loadData(){
$.ajax({
type: 'POST',
url: '".$this->createUrl('controller/action')."',
success:
function (data){
list.html(data);
}
});
}
");
?>
h3rm
3
I tried to modify the code that you provide. and I want to display the data in the process of the Controller.
<input type="submit" value="Submit" id="btn" />
<div id="test"></div>
<?php
Yii::app()->clientScript->registerScript('show', "
$('#btn').click(function(){
loadData();
});
function loadData(){
$.ajax({
type: 'POST',
url: '".$this->createUrl('site/member')."',
success:
function (data){
$('#test').html(data);
}
});
}
");
?>
and this Controller side :
public function actionMember(){
return "Welcome";
}
but "Welcome" not display
tri
(tri - Tommy Riboe)
4
Use echo instead of return
public function actionMember()
{
echo "Welcome"; // essential
Yii::app()->end(); // recommended
}
/Tommy
h3rm
6
there is the question again.
how to send parementer to controller.
for example:
public function actionMember()
{
echo "Welcome ";
Yii::app()->end();
}
i wanto to add ‘echo "Welcome ";’ to be ‘echo “Welcome hermans”’
and hermans be obtained from view.
i tried modify code like this:
unction loadData(){
$.ajax({
type: 'POST',
url: '".$this->createUrl('site/member')."',
data: 'nm=Hermans',
success:
function (data){
$('#test').html(data);
}
});
}
Controller:
public function actionMember(){
echo "Welcome " . $nm;
Yii::app()->end();
}
The variable "$nm" is not created automatically, you have to assign it in your controller:
if(isset($_GET['nm'])) {
$nm = $_GET['nm'];
echo "Welcome " . $nm;
} else {
echo "Welcome";
}