JQuery get data

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




<?php

Yii::app()->clientScript->registerScript('show', "

	function loadData(){

    $.ajax({

        type: 'POST',

        url: '".$this->createUrl('controller/action')."',

        success:

            function (data){

                list.html(data);

            }

    });

    

}

");

?>



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

Use echo instead of return




public function actionMember()

{

  echo "Welcome";    // essential

  Yii::app()->end(); // recommended

}



/Tommy

Thank you, very helpful

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";


}

thank you, can run well