javascript - AngularJS Not able to pass model data to server model appears as empty string -



javascript - AngularJS Not able to pass model data to server model appears as empty string -

i'm trying send simple info server. take received server info used create dynamic forms, clean unnecessary keys using delete formdata['not_needed'], , wanted add together model has been created before posting server, when check info objects model key i'm trying add together empty string. can either send 1 or other, can't seem add together 1 object key-value pair.

// abridged version var formdata = $scope.responsedata; // original server info build forms delete formdata['config_data']; // remove unnecessary keys formdata.model = $scope.formmodel; // add together model key $http.post('/restful/api', formdata).then(function(success) {...}, function(error) {...});

the output of passed info server looks like:

{ id: "1", type: "type_of_form", name: "name_of_package", model: "" } // model empty

is issue using $scope?

update

even when hardcode outgoing keys:

var packagedata = { "packageid": $scope.formdata.id, // makes server "desc": $scope.formdata.desc, // makes server "data": $scope.formmodel // empty string }

but formmodel filled dumby form info when logged console , printed out screen using filter { formmodel | json } looks like:

formmodel = { "document_date": "1234", "first_name0": "1", "first_name1": "2", "first_name2": "3", "first_name3": "4" }

it you're running by-now famous "angularjs cannot form-url-encode info posts default" pitfall; if so, you'll need before seek , post:

.config(['$httpprovider', function ($httpprovider) { // intercept post requests, convert standard form encoding $httpprovider.defaults.headers.post["content-type"] = "application/x-www-form-urlencoded"; $httpprovider.defaults.transformrequest.unshift(function (data, headersgetter) { var key, result = []; (key in data) { if (data.hasownproperty(key)) { result.push(encodeuricomponent(key) + "=" + encodeuricomponent(data[key])); } } homecoming result.join("&"); }); }]);

via how can post info form info instead of request payload?

javascript angularjs angular-ngmodel

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -