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 !
相关问答
更多Laravel Backpack CRUD无法正常工作(Laravel Backpack CRUD not working)
Mozilla的音频(Mozilla's audio)
在PHP中使用Mozilla Open Badges .png图像创建(Mozilla Open Badges .png image creation in PHP)
无法在Laravel Backpack PageManager中插入/更新新字段(Not able to insert/update new fields in Laravel Backpack PageManager)
使用Mozilla Backpack Connect API和PHP(Use the Mozilla Backpack Connect API with PHP)
如何修改Laravel-Backpack / Settings中的字段(How to modify field in Laravel-Backpack/Settings)
当我尝试登录Mozilla的背包时,我得到“无法通过browserID验证!”我该如何解决这个问题?(When I try to sign in to Mozilla's Backpack I get “Could not verify with browserID!” How can I fix this?)
如何直接进入Backpack-Laravel的编辑部分?(How to go directly in the edit section in Backpack-Laravel?)
SQL ERROR ='where子句'中的未知列'Backpack'...提示?(SQL ERROR = Unknown column 'Backpack' in 'where clause'…tips?)
BackPack PageManager fields.select_page_template未找到(BackPack PageManager fields.select_page_template not found)
相关文章
更多[IT教程网]Ajax和jQuery基础入门视频[已经完结]
ajax数据安全的问题
jquery ajax做的项目,如何实时更新当前位置所在的面包屑导航?
jQuery ,ajax,中文传值传不到的问题,第一次使用
jquery ajax方法url请求action没有返回json数据。
传智播客冯威Ajax和jQuery基础入门视频教程
AJAX问题
ajax验证用户注册
jquery 问题
AJAX JSON 乱码
最新问答
更多python的访问器方法有哪些
使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
透明度错误IE11(Transparency bug IE11)
linux的基本操作命令。。。
响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(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
Copyright ©2023
peixunduo.com All
Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!