很多时候我们需要用ajax提交post数据,angularjs与jq类似,也有封装好的post。
但是jQuery的post明显比angularjs的要简单一些,人性化一些。
两者看起来没什么区别,用angularjs的$http提交的数据,在php服务器端却无法通过$_REQUEST/$_POST获取到。
这是因为两者的post对header的处理有所不同……jQuery会把作为JSON对象的myData序列化,而Angular不会。
解决方案:
修改Angular的$httpProvider的默认处理(最完美的解决方案)
angular.module('MyModule', [], <span style="color: #0000ff;">function</span><span style="color: #000000;">($httpProvider) { </span><span style="color: #008000;">//</span><span style="color: #008000;"> Use x-www-form-urlencoded Content-Type</span> $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'<span style="color: #000000;">; </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * The workhorse; converts an object to x-www-form-urlencoded serialization. * @param {Object} obj * @return {String} </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">var</span> param = <span style="color: #0000ff;">function</span><span style="color: #000000;">(obj) { </span><span style="color: #0000ff;">var</span> query = ''<span style="color: #000000;">, name, value, fullSubName, subName, subValue, innerObj, i; </span><span style="color: #0000ff;">for</span>(name <span style="color: #0000ff;">in</span><span style="color: #000000;"> obj) { value </span>=<span style="color: #000000;"> obj[name]; </span><span style="color: #0000ff;">if</span>(value <span style="color: #0000ff;">instanceof</span><span style="color: #000000;"> Array) { </span><span style="color: #0000ff;">for</span>(i=0; i<value.length style="color: #000000;">i) { subValue =<span style="color: #000000;"> value[i]; fullSubName </span>= name + '[' + i + ']'<span style="color: #000000;">; innerObj </span>=<span style="color: #000000;"> {}; innerObj[fullSubName] </span>=<span style="color: #000000;"> subValue; query </span>+= param(innerObj) + '&'<span style="color: #000000;">; } } </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(value <span style="color: #0000ff;">instanceof</span><span style="color: #000000;"> Object) { </span><span style="color: #0000ff;">for</span>(subName <span style="color: #0000ff;">in</span><span style="color: #000000;"> value) { subValue </span>=<span style="color: #000000;"> value[subName]; fullSubName </span>= name + '[' + subName + ']'<span style="color: #000000;">; innerObj </span>=<span style="color: #000000;"> {}; innerObj[fullSubName] </span>=<span style="color: #000000;"> subValue; query </span>+= param(innerObj) + '&'<span style="color: #000000;">; } } </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span>(value !== undefined && value !== <span style="color: #0000ff;">null</span><span style="color: #000000;">) query </span>+= encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&'<span style="color: #000000;">; } </span><span style="color: #0000ff;">return</span> query.length ? query.substr(0, query.length - 1<span style="color: #000000;">) : query; }; </span><span style="color: #008000;">//</span><span style="color: #008000;"> Override $http service's default transformRequest</span> $httpProvider.defaults.transformRequest = [<span style="color: #0000ff;">function</span><span style="color: #000000;">(data) { </span><span style="color: #0000ff;">return</span> angular.isObject(data) && String(data) !== '[object File]' ?<span style="color: #000000;"> param(data) : data; }]; });</span></value.length>

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.

HTML is used to build websites with clear structure. 1) Use tags such as, and define the website structure. 2) Examples show the structure of blogs and e-commerce websites. 3) Avoid common mistakes such as incorrect label nesting. 4) Optimize performance by reducing HTTP requests and using semantic tags.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
