Good morning, I’ve been working on an ajaxButton to save a record to my database. A value from this record comes from the selected row of a CGridView, other components works fine, even added an alert on js to verify it was receiving the right value, the one seems right.
However I get no errors or notifications at all, and code seems not to be working at all, cause it doesn’t even returns a data.msg. I’m still a bit confused on ajaxButton structure after reading some wiki and posts, can you give me a hand on what’s wrong please?
I’m not sure im following your question, but in Your controller action your not returning anything to the view
'success'=>'js:function(data){ //this means the result will be in an array named data
if(data.result=="success"){ //if result variable is success,which it currently isnt since u // havent set it in the controller
do something on success, like redirect
}else{
$("#result").html(data.msg);
}
So what you want to do is, return info from the controller action in a way javascript can understand, for that is json_encode();
Now u will be able to see "failed" or "Saved"in your #result div.
If you see failed, you know the request to the controller was successfull,but you for some reason couldnt save the data (validation rules,empty values or something like that)
If you see "Saved" all is fine:p
If u dont see anything at all, its something wrong with the request to your controller, lock in firebug console (if u use firefox,else all browsers has something similair) for javascript errors,its a must when working with ajax,else massive headaches will arrive
Thank you very much for your answers, I’ve been working a bit after this one and I got this piece of code (I’ll be making corrections on the one I posted before and I’ll add feedback while you read this one since at least I have some debugging options with this one )
Sorry for delay was testing the above solutions. Yes, I read Sampa’s post and he was right, headaches were coming now I get access to the controller, but the value from selected item in grid view is nos passing correctly, I know it because I tried with a static value before and worked, here’s my actual code
I have the feeling I need to convert the value from variable somehow, but I don’t know how at the moment, trying on it while I read the wiki Gerhard Liebenberg posted trying to find out how
Any advice would be greatly appreciated, thank you in advance!
Update: after some time debugging jquery class as I suspected it was taking literally $.fn.yiiGridView.getSelection("amigos-grid") as the value to pass, not the content of the variable
I fixed it setting data type as a script, and returning this property inside a variable so it receives the variable content instead a string with $.fn.yiiGridView.getSelection("amigos-grid") , this way:
The only problem I have now is I don’t know how to refresh data, I tried with $this->refresh() however it crashes I don’t know why thank you very much for your help, and if you know how could I refresh the view components would be wonderful thank you in advance
Than you for answer, I’m sorry about that mistake I just learned using ajax with JQuery basics today so I’m still feel a bit lost on how functions exactly works, and haven’t been able to refresh the page yet, could anyone give me some input about it?