翻译-让ng的$http服务与jQuerr.ajax()一样易用
$http service shorthand functions ($http.post(), etc.) don’t appear to be swappable with the jQuery equivalents (jQuery.post(), etc.) even though the respective manuals imply identical usage. That is, if your jQuery code looked like this before:{ foo: 'bar' } params from the AngularJS request.Content-Type: x-www-form-urlencoded and the familiar foo=bar&baz=moe serialization. AngularJS, however, transmits data using Content-Type: application/json and { "foo": "bar", "baz": "moe" } JSON serialization, which unfortunately some Web server languages—notably PHP—do not unserialize natively.Content-Type: x-www-form-urlencoded 将data转码为foo=bar&baz=moe 的形式。ng则是Content-Type: application/json 来发送{ "foo": "bar", "baz": "moe" } 的JSON串,这使得服务器端(尤其是PHP)无法解读这样的数据。$http service to let us impose x-www-form-urlencoded on all our transmissions. There are many solutions people have offered thus far on forums and StackOverflow, but they are not ideal because they require you to modify either your server code or your desired usage pattern of $http. Thus, I present to you the best possible solution, which requires you to change neither server nor client code but rather make some minor adjustments to $http‘s behavior in the config of your app’s AngularJS module:x-www-form-urlencoded 发送数据,关于这点很多人提供了解决办法,但都不太理想,因为你不得不去修改你的服务器代码或者$http的代码。介于此,我给出了可能是最优的解决方案,前后端的代码均无需修改:jQuery.param() in place of the above homegrown param() function; it will cause havoc when you try to use AngularJS $resourcebecause jQuery.param() will fire every method on the $resource class passed to it! (This is a feature of jQuery whereby function members of the object to parametrize are called and the return values are used as the parametrized values, but for our typical use case in AngularJS it is detrimental since we typically pass “real” object instances with methods, etc.)$http service shorthand functions ($http.post(), etc.) don’t appear to be swappable with the jQuery equivalents (jQuery.post(), etc.) even though the respective manuals imply identical usage. That is, if your jQuery code looked like this before:{ foo: 'bar' } params from the AngularJS request.Content-Type: x-www-form-urlencoded and the familiar foo=bar&baz=moe serialization. AngularJS, however, transmits data using Content-Type: application/json and { "foo": "bar", "baz": "moe" } JSON serialization, which unfortunately some Web server languages—notably PHP—do not unserialize natively.Content-Type: x-www-form-urlencoded 将data转码为foo=bar&baz=moe 的形式。ng则是Content-Type: application/json 来发送{ "foo": "bar", "baz": "moe" } 的JSON串,这使得服务器端(尤其是PHP)无法解读这样的数据。$http service to let us impose x-www-form-urlencoded on all our transmissions. There are many solutions people have offered thus far on forums and StackOverflow, but they are not ideal because they require you to modify either your server code or your desired usage pattern of $http. Thus, I present to you the best possible solution, which requires you to change neither server nor client code but rather make some minor adjustments to $http‘s behavior in the config of your app’s AngularJS module:x-www-form-urlencoded 发送数据,关于这点很多人提供了解决办法,但都不太理想,因为你不得不去修改你的服务器代码或者$http的代码。介于此,我给出了可能是最优的解决方案,前后端的代码均无需修改:jQuery.param() in place of the above homegrown param() function; it will cause havoc when you try to use AngularJS $resourcebecause jQuery.param() will fire every method on the $resource class passed to it! (This is a feature of jQuery whereby function members of the object to parametrize are called and the return values are used as the parametrized values, but for our typical use case in AngularJS it is detrimental since we typically pass “real” object instances with methods, etc.)翻译-让ng的$http服务与jQuerr.ajax()一样易用的更多相关文章
- [翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间
[翻译]利用C#获取终端服务(Terminal Services)会话的闲置时间 作者:Tuuzed(土仔) 发表于:2008年2月29日版权声明:可以任意转载,转载时请务必以超链接形式标明文章原 ...
- caffe官网的部分翻译及NG的教程
Caffe原来叫:Convolutional Architecture for Fast Feature Embedding 官网的个人翻译:http://blog.csdn.net/fengbing ...
- ASP.NET实现二维码 ASP.Net上传文件 SQL基础语法 C# 动态创建数据库三(MySQL) Net Core 实现谷歌翻译ApI 免费版 C#发布和调试WebService ajax调用WebService实现数据库操作 C# 实体类转json数据过滤掉字段为null的字段
ASP.NET实现二维码 using System;using System.Collections.Generic;using System.Drawing;using System.Linq;us ...
- jsp作为服务端,ajax请求回应
刚学ajax,想以jsp作为服务端,来回应ajax的请求: 代码如下: <!DOCTYPE html> <html> <head lang="en"& ...
- 让AngularJS的$http 服务像jQuery.ajax()一样工作
让AngularJS的$http 服务像jQuery.ajax()一样工作 $http的post . 请求默认的content-Type=application/json . 提交的是json对象的字 ...
- 在 vue cli3 的项目中配置双服务,模拟 ajax 分页请求
最近安装了下vue cli3版本,与 cli 2 相比,文件少了,以前配置方法也不管用了.demo 中的大量的数据,需要做成 ajax 请求的方式来展示数据,因此,需要启动两个服务,一个用作前端请求, ...
- java 服务端解决ajax跨域问题
//过滤器方式 可以更改为拦截器方式public class SimpleCORSFilter implements Filter { public void doFilter(ServletRequ ...
- 使用javascript把图片转成base64位编码,然后传送到服务端(ajax调用的接口基于drupa7)
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- 【翻译】了解ASP.NET MVC中的Ajax助手
原文:Understanding AJAX Helpers in ASP.NET MVC 作者: Shailendra Chauhan works as Software Analyst at rep ...
随机推荐
- BZOJ1057 [ZJOI2007]棋盘制作(极大化思想)
1057: [ZJOI2007]棋盘制作 Time Limit: 20 Sec Memory Limit: 162 MB Submit: 1848 Solved: 936 [Submit][Sta ...
- LaTeX手动安装宏包(package)以及生成帮助文档的整套流程
注意:版权所有,转载请注明出处. 我使用的是ctex套装,本来已经自带了许多package,但是有时候还是需要使用一些没有预装的宏包,这时就需要自己安装package了.下载package可以从CTA ...
- [git] git 分支管理和工作流程
分支管理 列举本地分支.下面的 * 是 HEAD 所指向的分支,标识当前工作目录所用的分支.其他分支隐藏在 git 仓库中,通过 git checkout 命令才能访问和修改. $ git branc ...
- 解放程序猿宝贵的右手(或者是左手) ——Android自动化测试技巧
解放双手--Android自动化测试 - eclipse_xu - 博客频道 - CSDN.NET 解放程序猿宝贵的右手(或者是左手) --Android自动化测试技巧
- java传递json数据到前台jsp
在数据传输流程中,json是以文本,即字符串的形式传递的,而JS操作的是JSON对象,所以,JSON对象和JSON字符串之间的相互转换是关键.例如: JSON字符串: var str1 = '{ &q ...
- linux下使用fscanf实现scanf
首先,我们知道,linux下的scanf标准库函数是一个可变参的函数,那么,我们自己要实现一个scanf也必须是一个可变参的. 其实,在liunx的库中就提供了这样的的宏,来方便我们自己来实现变参函数 ...
- 在C#中使用InputBox
以前用VB编程常用InputBox,现在学了C#,竟然找不到它了--后来到网上查到了,现在贡献给大家:1.首先要添加引用Microsoft.VisualBasic2.命名空间 Using Micros ...
- Android中关于在onDrow或者onMeasure中创建对象提示Avoid object allocations during draw/layout operations (preallocate and reuse instead) 问题
在实际开发中Android中自带的控件有时无法满足我们的需求,这时就需要我们重写控件来实现我们想要的功能. 还有个关于UI体验的问题,就是在onDraw()函数中最好不要去创建对象,否则就提示下面的警 ...
- (转载)JavaScript中面向对象那点事
鉴于自己在JavaScript这方面比较薄弱,所以就找了一本书恶补了一下(被称为犀利书的JavaScript权威指南).书的内容虽然多了点,但这也充分说明了js中的东西还是挺多的.虽然我们的定位不是前 ...
- Android热门网络框架Volley详解
.Volley简介 volley的英文意思为‘群发’.‘迸发’.Volley是2013年谷歌官方发布的一款Android平台上的网络通信库.Volley非常适合一些数据量不大,但需要频繁通信的网络操作 ...