Answer the question
In order to leave comments, you need to log in
Yii+Jquery $.post?
Good afternoon.
I'm trying to send data to the server using the $.post
method
<script>
$('#add_element_btn').click(function()
{
$.post("<? echo Yii::app()->baseUrl; ?>/catalog/additem/", {
uuid: <? echo $catalog->uuid; ?>,
name : $('#input_name').val()
},
function(data){
alert(data.status);
}, "json");
});
</script>
<?<br>
class CatalogController extends CController<br>
{<br>
<br>
public function actionAdditem()<br>
{<br>
<br>
// $catalog = Catalogs::model()->findbyPk(1);<br>
<br>
print json_encode(array("status"=>'ok'));<br>
}<br>
}<br>
?><br>
Answer the question
In order to leave comments, you need to log in
Instead of "<? echo Yii::app()->baseUrl; ?>/catalog/additem/" it's better to use CController::createUrl('catalog/additem')
$catalog = Catalogs::model()->findbyPk(1);
generates some kind of output, it's obvious
1) Although this is not related to your question, use registerScript to publish JS.
2) Use relative paths in JS - you're better off.
3) To see what's wrong, open Firebug/Dragonfly or whatever it is with your hand on the network tab and see the response from the server.
Have you tried to see what comes from the server when you uncomment it? Or do you like to guess at random what the problem is? We take _any_ browser and look at the result of Ajax, without any alerts and such nonsense, we see the result and we don’t have to ask what the problem is. Like little children, by God.
And the model is exactly called Catalogs and just try to follow the url that the request sends, does it return errors
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question