john john - 1 year ago 113
AngularJS Question

How to send POST with multiple params in angularjs?

I want to send multiple parameters using angularjs HTTP post service.
This is my function to send post using in my project

function getListObject(table,language) {
var url=API_URL+table+"?";
var companyTemp={company_id:40743};
var languageTemp={language_id:language}
var cm = "list";
var dtJSON = JSON.stringify({table: JSON.parse(JSON.stringify()),company:JSON.parse(JSON.stringify(companyTemp)),languages: JSON.parse(JSON.stringify(languageTemp))});
var data = $.param({
cm: cm,
dt: dtJSON
return $, handleError('Error get list'));}

Example my url is: localhost:8080/api/product?cm=list&dt={product:{},company:{company_id:40743},languages:{language_id:"en"}}

When I use above function, I write: Service.getListObject("products","en").
I have a problem in this line:

var dtJSON = JSON.stringify({table: JSON.parse(JSON.stringify(companyTemp)),languages: JSON.parse(JSON.stringify(languageTemp))});

I want result dtJSON this line is:


But I receive this :


How to fix this?

Answer Source

Documentation : $http

$, data, config);

$http will handle itself the JSON parsing thus you do not need to do it yourself

function getListObject(table, language) {
    var url = API_URL;
    return $ , {company_id : 40743, language_id : language, cm : "list"});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download