Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Js+Ajax Calling Action From Outside The Application

$
0
0
after finishing the web application I want to make a phoneGap app
that send/recieve JSON to my controllers

for start

1) in the same controller I add other action
public function actionCreateCar_Mobile() {
$model = new Car;


$model->CarId= 1;
$model->CarColor= 'RED';

return CJSON::encode($model);
}

2)
write JS to send ajax request to get that model

$(document).ready(function () {
$('#btn').bind('click',function(){ getCar()});

function createNewUser() {
$.ajax({
type: "GET",
url: "http://localhost/VS/index.php/Car/CreateCar_Mobile",
cache: false,
data: '' ,
success: onSuccess,
error: onError
});
return false;}
function onSuccess(data, status){ alert(data); }
function onError(data, status)
{ alert("Error Submitting Form"); }
});


is this a right wat to do what I'm trying to do ?
when I click the btn it give me an empty alert ! why did not show the json from the action
what is the best way to handle authentication

Viewing all articles
Browse latest Browse all 18717

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>