jquery和ajax的问题(Problem with jquery and ajax)
我有两个功能:
$(function() { $(".deactivated").click(function() { var Container = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "<?php echo site_url('social/activate') ?>", type: "POST", data: string, cache: false, success: function(){ Container.fadeOut(1000, function(){ $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){ $(this).hide().fadeIn(700); $(this).click(); }) }); } }); return false; }); }); $(function() { $(".activated").click(function() { var Container = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "<?php echo site_url('social/deactivate') ?>", type: "POST", data: string, cache: false, success: function(){ Container.fadeOut(1000, function(){ $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){ $(this).hide().fadeIn(700); }) }); } }); return false; }); });
一个是激活链接,另一个是停用链接。 功能正常,但是当激活或取消激活链接时,不能再次单击它来更改它(需要刷新页面才能使功能再次工作)。 我需要做些什么来使它工作?
I have two functions:
$(function() { $(".deactivated").click(function() { var Container = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "<?php echo site_url('social/activate') ?>", type: "POST", data: string, cache: false, success: function(){ Container.fadeOut(1000, function(){ $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){ $(this).hide().fadeIn(700); $(this).click(); }) }); } }); return false; }); }); $(function() { $(".activated").click(function() { var Container = $(this).parent(); var id = $(this).attr("id"); var string = 'id='+ id ; $.ajax({ url: "<?php echo site_url('social/deactivate') ?>", type: "POST", data: string, cache: false, success: function(){ Container.fadeOut(1000, function(){ $(this).load("<?php echo site_url('social/social_icon') ?>", {id: id}, function(){ $(this).hide().fadeIn(700); }) }); } }); return false; }); });
One is to activate link and other is to deactivate it. Functions are working fine, but when link is activated or deactivated, it can't be clicked again to change it (page needs to be refreshed in order for functions to work again). What I need to do to make it work?
原文:https://stackoverflow.com/questions/7580522
最满意答案
我搜索了几个小时! 解决方案非常简单但不那么明显......
在这一行:
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
你必须使用json_encode()
而不是http_build_query()
!所以这样做:
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
它的工作原理! 好极了 !I've searched for hours ! The solution is really simple but not so obvious...
On this line :
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
you have to usejson_encode()
instead ofhttp_build_query()
!So doing like this :
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
and it works ! Yay !
相关问答
更多-
我想让我的答案非常详细,所以这就是我从一开始就开始的原因。 我使用的CRUD背包的版本是^ 3.2。 看看这个文件your-project/vendor/backpack/crud/src/CrudServiceProvider.php是的我知道类名不是CRUD而是CrudServiceProvider 。 那是因为他们在CrudServiceProvider有register方法,并在其中执行$loader->alias('CRUD', \Backpack\CRUD\CrudServiceProvider ...
-
Mozilla的音频(Mozilla's audio)[2022-07-13]
mozSetup和mozWriteAudio需要Firefox 4。 根据这个页面 ,这些方法被标记为[需要壁虎2.0] [非标准]。 Gecko 2.0首次在Firefox 4.0中使用。 mozSetup and mozWriteAudio need Firefox 4. According to this page, those methods are marked as [Requires Gecko 2.0] [Non-standard]. Gecko 2.0 was first used in ... -
您可以使用PHP库Imagick手动将元数据添加到.png文件中。 请检查这个自定义小型库如何使用它: https : //github.com/jmunozdev/php-tiny-openbadges-image-baker $im = new Imagick($image_url); // Set the image properties. $im->setimageproperty('openbadges', $this->assertionJsonUrl); // Return the final ...
-
PageManager背后的理念是将特定于模板的所有内容存储在数据库的“extras”列中,作为JSON。 不在他们自己的专栏内。 这样,您不需要在表中提供仅满足一个模板的列。 如果你: 删除PageCrudController中的store()和update()方法; 删除content1-header','content1','content2-header','content2','content3-header','content3','content4-header','content4','co ...
-
我搜索了几个小时! 解决方案非常简单但不那么明显...... 在这一行: curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); 你必须使用json_encode()而不是http_build_query() ! 所以这样做: curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); 它的工作原理! 好极了 ! I've searched for hours ! The solut ...
-
你的代码对我有用。 你确定你最后没有错过任何一个副词吗? {"name":"value","label":"Value", "title":"Lightbox" ,"type":"select_from_array", "options":{"lightbox":"lightbox","colorbox1":"colorbox1"}} Your code worked for me. Are you sure you didn't miss a paranthesis at the end? {"name ...
-
该解决方案有效。 我在Mozilla支持论坛上找到了它。 信用完全归功于用户的角色。 You can reload web page(s) and bypass the cache to refresh possibly outdated or corrupted files. Hold down the Shift key and left-click the Reload button Press "Ctrl + F5" or press "Ctrl + Shift + R" (Windows,Lin ...
-
如何直接进入Backpack-Laravel的编辑部分?(How to go directly in the edit section in Backpack-Laravel?)[2022-02-16]
如果您的意思是点击侧边栏中的用户名,则应该去编辑该用户,您可以通过在/resources/views/vendor/backpack/base/inc/sidebar.blade.php上放置链接。 I do not know if it might be the correct way. But it's the only way I've found to accomplish what I had in mind. public function index() { $this->cr ... -
SQL ERROR ='where子句'中的未知列'Backpack'...提示?(SQL ERROR = Unknown column 'Backpack' in 'where clause'…tips?)[2021-11-23]
您需要在查询中引用$ name $query = 'SELECT id, location_id, name, description, create_date, update_date, room, owner, finder, status' . ' FROM stuff' . ' WHERE name = "' . $name . '"'; // ^ ^ 但是,最好使用预备语句来防止sql注入和其他人 $query = 'SEL ... -
创建名为PageTemplates.php的新文件并替换app目录中的现有文件。 之后,您可以复制以前的代码。 Create new file named PageTemplates.php and replace the existing in the app directory. After that you may copy the previous code.