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
2024-04-21 09:04

满意答案

我搜索了几个小时! 解决方案非常简单但不那么明显......

在这一行: 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 use json_encode() instead of http_build_query() !

So doing like this : curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); and it works ! Yay !

相关问答

更多

Laravel Backpack CRUD无法正常工作(Laravel Backpack CRUD not working)

我想让我的答案非常详细,所以这就是我从一开始就开始的原因。 我使用的CRUD背包的版本是^ 3.2。 看看这个文件your-project/vendor/backpack/crud/src/CrudServiceProvider.php是的我知道类名不是CRUD而是CrudServiceProvider 。 那是因为他们在CrudServiceProvider有register方法,并在其中执行$loader->alias('CRUD', \Backpack\CRUD\CrudServicePro...

Mozilla的音频(Mozilla's audio)

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 use...

在PHP中使用Mozilla Open Badges .png图像创建(Mozilla Open Badges .png image creation in PHP)

您可以使用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 ...

无法在Laravel Backpack PageManager中插入/更新新字段(Not able to insert/update new fields in Laravel Backpack PageManager)

PageManager背后的理念是将特定于模板的所有内容存储在数据库的“extras”列中,作为JSON。 不在他们自己的专栏内。 这样,您不需要在表中提供仅满足一个模板的列。 如果你: 删除PageCrudController中的store()和update()方法; 删除content1-header','content1','content2-header','content2','content3-header','content3','content4-header','content4...

使用Mozilla Backpack Connect API和PHP(Use the Mozilla Backpack Connect API with PHP)

我搜索了几个小时! 解决方案非常简单但不那么明显...... 在这一行: 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 ...

如何修改Laravel-Backpack / Settings中的字段(How to modify field in Laravel-Backpack/Settings)

你的代码对我有用。 你确定你最后没有错过任何一个副词吗? {"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? {...

当我尝试登录Mozilla的背包时,我得到“无法通过browserID验证!”我该如何解决这个问题?(When I try to sign in to Mozilla's Backpack I get “Could not verify with browserID!” How can I fix this?)

该解决方案有效。 我在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" (Window...

如何直接进入Backpack-Laravel的编辑部分?(How to go directly in the edit section in Backpack-Laravel?)

如果您的意思是点击侧边栏中的用户名,则应该去编辑该用户,您可以通过在/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() { $thi...

SQL ERROR ='where子句'中的未知列'Backpack'...提示?(SQL ERROR = Unknown column 'Backpack' in 'where clause'…tips?)

您需要在查询中引用$ name $query = 'SELECT id, location_id, name, description, create_date, update_date, room, owner, finder, status' . ' FROM stuff' . ' WHERE name = "' . $name . '"'; // ^ ^ 但是,最好使用预备语句来防止sql注入和其他人 $query =...

BackPack PageManager fields.select_page_template未找到(BackPack PageManager fields.select_page_template not found)

创建名为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.

相关文章

更多

[IT教程网]Ajax和jQuery基础入门视频[已经完结]

视频介绍: 本视频是Ajax和jQuery基础入门视频,该视频针对接触过javaScript基础 ...

ajax数据安全的问题

我在一个网页中使用jquery里的ajax函数做ajax效果,一般会按照参数格式填写url(还有其他参 ...

jquery ajax做的项目,如何实时更新当前位置所在的面包屑导航?

国内国外搜索了很多资料,但都没找到这方面的,不知道谁有好的解决方案呢? 项目是jquery ajax ...

jQuery ,ajax,中文传值传不到的问题,第一次使用

ajax.html,比如我把jsp中的tom改为张三,然后在ajax.html中可以输入张三,显示数据 ...

jquery ajax方法url请求action没有返回json数据。

具体代码如下: jquery代码 $(function(){ $(&quot;#submButto ...

传智播客冯威Ajax和jQuery基础入门视频教程

本视频是Ajax和jQuery基础入门视频,该视频针对接触过javaScript基础的学员录制,授课讲 ...

AJAX问题

我的问题是这样 两个下拉框 区县 &lt;/td&gt; &lt;td width=&quot; ...

ajax验证用户注册

gui求大哥们给一个ajax验证用户的+java后台的代码实例 加详细注解 新手学习ajax 我另外再 ...

jquery 问题

[color=green] [size=medium][size=small][size=medium ...

AJAX JSON 乱码

网上下了一个JS、功能是把FORM里的内容序列化为JSON、用AJAX方式提交到后台 JS比较小巧 ...

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640