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


I am trying to send some simple data to the server. I dynamically create server data received I used to clean up unnecessary keys by quickly using deleted formatta ['not_needed'], and then I wanted to add that model that was created before posting on the server, but when I The key to the data objects model that I want to add I am trying to always have an empty string. I can either send one or the other, but can not add one object to another as a value-price pair.

  // aligned version var formadata = $ scope.responseData; / / Form data ['config_data'] to delete the original server data form format; // Remove unnecessary keys form.data.model = $ scope.formModel; // Add Model key $ http.post ('/ restful / api', formData). Then (function (success) {...}, function (error) {...});  

The output of the passed data from the server looks like this:

  {id: "1", type: "type_of_form", name: "name_of_package ", Model:" "} // Model is always empty  

Is this an issue using the $ scope?

UPDATE

Even when I hardcode the outgoing keys:

  var package data = { "Packageid": $ scope.formData.id, // makes it "desc" server: $ scope.formData Desc, // also makes it server "data": $ scope.formModel // Just an empty string }  

But when logging in and being printed on the console, formModel is full of some dummy form data on the screen using a filter {formModel | "3", "2", "first_name2": "2", "first_name1": "1" "first_name3": "4"}

It may be that you are now running in the well-known "AngularJS form-url-encoded data which it posts by default" if so, You must do this before you try and post:

  .config (['$ httpProvider', function ($ httpProvider)) // // Block post request, convert to standard Form encoding $ httpProvider.defaults.headers.post ["Content-Type "] =" Application / x-www-form-urlencoded "; $ HttpProvider.defaults.transformRequest.unshift (function (data, headgator) {var key, result = () (key in data) {if (data.hasOwnProperty (key)} {result.push (encodeurIComponent (key) + "= "+ EncodeurIComponent (data [key]))}} return result.join (" & amp; ");});}]);     via  


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -