Angular post parameter passing backend php cannot receive-fan Dingwen

Source: Internet
Author: User
Angular post parameter passing backend php cannot receive-fan Dingwen many times we need to submit post Data Using ajax. angularjs is similar to jq and has encapsulated post.

However, jQuery post is much simpler and more user-friendly than angularjs post.

There seems to be no difference between the two. The data submitted with $ http from angularjs cannot be obtained through $ _ REQUEST/$ _ POST on the php server.

This is because the post processing of the header is different between the two ...... JQuery serializes myData as a JSON object,Angular does not.

Solution:

Modify the default processing of Angular $ httpProvider (the most perfect solution)

angular.module('MyModule', [], function($httpProvider) {  // Use x-www-form-urlencoded Content-Type  $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';   /**   * The workhorse; converts an object to x-www-form-urlencoded serialization.   * @param {Object} obj   * @return {String}   */   var param = function(obj) {    var query = '', name, value, fullSubName, subName, subValue, innerObj, i;          for(name in obj) {      value = obj[name];              if(value instanceof Array) {        for(i=0; i
 
  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.