How do I POST urlencoded form data with $http without jQuery?

后端 未结 11 2511
生来不讨喜
生来不讨喜 2020-11-21 23:27

I am new to AngularJS, and for a start, I thought to develop a new application using only AngularJS.

I am trying to make an AJAX call to the server side, using

11条回答
  •  半阙折子戏
    2020-11-22 00:06

    Though a late answer, I found angular UrlSearchParams worked very well for me, it takes care of the encoding of parameters as well.

    let params = new URLSearchParams();
    params.set("abc", "def");
    
    let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded'});
    let options = new RequestOptions({ headers: headers, withCredentials: true });
    this.http
    .post(UrlUtil.getOptionSubmitUrl(parentSubcatId), params, options)
    .catch();
    

提交回复
热议问题