من از فریمورک codeigniter استفاده میکنم و میخوام اطلاعاتی رو به صورت ایجکس با فرمت جیسون و در جیکوئری به سرور ارسال کنم و وقتی سرور اوکی داد بعد نتیجه رو چاپ کنم نه اینکه فقط وقتی اطلاعات ارسال شدند در قسمت view این کدها رو دارم:
form_data = {
name : “ali”,
family:"mohamadi"
}
$.ajax({
type: 'POST',
url: my_controller/my_function,
data: form_data,
dataType: 'json',
success: function(data){
alert(data.message);
}
});
class my_controller extends CI_Controller {
protected function my_function()
{
$success = true;
if ($success == true)
{
$data = array('success'=> true,'message'=>'Success message!');
}
else
{
$data = array('success'=> false,'message'=>'Failure message!');
}
header("Content-Type: text/plain");
echo json_encode($data);
}
}
ولی الان فقط undefined نمایش میده باید چیکار کنم که درست شه
کدها رو هم نتونستم با ادیتور اینجا درست نمایش بدم ببخشید
form_data = {
name : “ali”,
family:"mohamadi"
}
$.ajax({
type: 'POST',
url: my_controller/my_function,
data: form_data,
dataType: 'json',
success: function(data){
alert(data.message);
}
});
:و در کنترولر
class my_controller extends CI_Controller {
protected function my_function()
{
$success = true;
if ($success == true)
{
$data = array('success'=> true,'message'=>'Success message!');
}
else
{
$data = array('success'=> false,'message'=>'Failure message!');
}
header("Content-Type: text/plain");
echo json_encode($data);
}
}
ولی الان فقط undefined نمایش میده باید چیکار کنم که درست شه
کدها رو هم نتونستم با ادیتور اینجا درست نمایش بدم ببخشید