2

I have this ajax formData:

data.formData = {action : 'process_uploads',filetitle : newtitle, filehash : file_hash, aspect : aspect, uploadlanguage : uploadlanguage, thefilesize : data.files[0].size};

I need to append more keys/values after this has already been declared AND submitted so I can submit it again. How can I do that?

i.e.

//declare original data
data.formData = {action : 'process_uploads',filetitle : newtitle, filehash : file_hash, aspect : aspect, uploadlanguage : uploadlanguage, thefilesize : data.files[0].size};

//submit form and gather result on success
var jqXHR = data.submit().success(function(result, textStatus, jqXHR){

  var json = JSON.parse(result);



  if(json.files[0].hash != file_hash ){

//NEED TO ADD MORE VARIABLES AND SUBMIT AGAIN

data.formData.retryfile = '1';
data.formData.hash = 'file_hash';
//this isn't working.


     data.submit();

}
0

1 Answer 1

2

Try:

let jsonData =  {action : 'process_uploads',filetitle : newtitle, filehash : file_hash, aspect : aspect, uploadlanguage : uploadlanguage, thefilesize : data.files[0].size};
jsonData.newfield =1;

console.log(jsonData);
data.formData = jsonData;

OR using Object.assign

let infoA = {action : 'process_uploads'};
let infoB = {newfield:'1'};


let jsonData = Object.assign(infoA, infoB);
console.log(jsonData);
data.formData = jsonData;

In your updated code:

//declare original data
var jsonData = {action : 'process_uploads',filetitle : newtitle, filehash : file_hash, aspect : aspect, uploadlanguage : uploadlanguage, thefilesize : data.files[0].size};
data.formData = jsonData;

//submit form and gather result on success
var jqXHR = data.submit().success(function(result, textStatus, jqXHR){

  var json = JSON.parse(result);


  var status = json['status'];


  if(json.files[0].hash != file_hash ){

   //NEED TO ADD MORE VARIABLES AND SUBMIT AGAIN

   jsonData.retryfile = '1';
   jsonData.hash = 'file_hash';

   data.formData = jsonData;

   data.submit();

}
Sign up to request clarification or add additional context in comments.

6 Comments

Here you are appending it before data.formData has been declared. I need to add it after it has been declared already and previously submitted.
You can define jsonData at any moment, and set to "data.formData" whenever you want.
Can you swap infoB with data.formData?
yes, you could swap or add more obj... Object.assign{{}, infoA , data.formData , {another:'x'} } ;
I updated it to make it more clear what I am trying to do.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.