benjiao
(Benjiao12)
May 16, 2012, 6:10am
1
Hi,
I’m having some trouble when i update a CGridView using
$.fn.yiiGridView.update();
as a success parameter in an ajax call.
I’m working on a page where i have a CActiveForm and a CGridView. The CActiveForm is used to add entries to the CGridView, which should be updated via jquery whenever an entry is added.
Here’s the script i use for submitting my form (updates the grid after submission):
$('#division-submit').click(function(){
$.ajax({
type:'POST',
url: '".Yii::app()->createUrl('division/create')."',
data:$('#new-division-form').serialize(),
success: function(){
$('#new-division-form')[0].reset();
$('.new-form').hide();
$.fn.yiiGridView.update('division-grid');
}
});
});
Whenever it is called, the gridview does not reload. instead, it hangs with the loading gif and this shows up in the Chrome console:
Uncaught TypeError: Object function (a,c){var d=[],e=function(a,<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />{b=f.isFunction(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='B)' />};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join("&").replace(bC,"+")} has no method 'querystring'
methods.update
Any ideas?
Thanks!
-Benjie
mdomba
(Maurizio Domba Cerin)
May 16, 2012, 7:17am
2
This code is not in the gridview JS… can you try to debug the call to the gridview update?
Try first to add some JS instruction after the call to update and set there a breakpoint to see if the error happens inside the update or even later…
Hello.
Where have you put this JS code? There’s something wrong with the url.
Are you sure it’s in a PHP string, because it looks like you are concatenating a static string with a dynamic url?
Edit: I mean it’s ok if your code is something like
some_php_code("
$('#division-submit').click(function(){
$.ajax({
type:'POST',
url: '" . Yii::app()->createUrl('division/create') . "', // the concatenation happens here
data:$('#new-division-form').serialize(),
success: function(){
$('#new-division-form')[0].reset();
$('.new-form').hide();
$.fn.yiiGridView.update('division-grid');
}
});
});
"); // end of your string wrapping function/method
cullensun
(Sunhongshuai)
October 16, 2012, 3:27am
4
I got this error, because I included another latest jquery.min.js, guess corrupted with Yii’s jquery
mroz
(Michal Masek)
November 13, 2012, 9:06pm
5
If you put something like this
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
inside your layout then you use cgridview, it loads its own jQuery. jquery.min.js then mess up $.param and the whole cgridview does not work.
My solution is to put
public $loadJQuery=true
in the controller and
<?php
if ($this->loadJQuery)
echo '<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>';
?>
into the layout file
and set
$this->loadJQuery=false
in every action using cgridview
mdomba
(Maurizio Domba Cerin)
November 13, 2012, 9:15pm
6
Mroz you can set Yii to not load jquery at all and load it yourself at all times… for this use the scriptMap property http://www.yiiframework.com/doc/api/1.1/CClientScript#scriptMap-detail
wesseling
(Wesseling)
October 11, 2013, 11:47am
7
In my case the cause of the problem was a missing library called "jquery.ba-bbq.js". It was missing, because I disabled it manually in the scriptMap config directive.
Also if your webroot/assets directory is not writable, that script will not be loaded and the jquery.yiigridview.js will generate the error you showed above.
Thanks a lot, it was my error;