0

I'm trying to gather information from all of the textareas on my page, and then put that information into an array so I can send to the server via ajax/json.

Although I am not quite sure how to go about doing it.

I'm not sure how to pull the information I need from the

Here is what I have so far:

Example of my HTML

 "<textarea id='tbObjective_" + counter + "' name='txtObjective' class='objectives' sequence='" + counter + "'></textarea>" 

jQuery:

    var objectiveList = [];
    $('.objectives').each(function (objective) {
        objectiveList.push({
            id: objective.id,
            sequence: objective.sequence,
            text: objective.val()
        });
    });

    $.ajax({
        type: "POST",
        url: url,
        dataType: "json",
        data: objectiveList 
    });

Any help would be appreciated

Thanks

4
  • 1
    And what exactly is your question? Commented Apr 25, 2013 at 19:31
  • Im not sure how to get all the info from the <textarea> and put into an array..thanks Commented Apr 25, 2013 at 19:42
  • Are you not getting the array or are you unable to send the proper array in your AJAX call? Commented Apr 25, 2013 at 19:48
  • I'm not getting the array, it's all empty. So I thought it had something to do with the way I was creating/populating it Commented Apr 25, 2013 at 19:59

3 Answers 3

2

you can proceed with the following procedure. i have used python django and html5 for the purpose

1. make a text box which is hidden and after generating  your json document set it in this text box (suppose id of textbox is "submit_json") than  use
$("#submit_json").val(JSON.stringify(formData, null, '\t')),  // (formData, null, '\t') this is js function that i have written for the ourpose

data = JSON.stringify({"jsonDoc":Generated JSON})

console.log(data);
$.ajax({

url: 'http://127.0.0.1:8000/catchjson/',
type: 'POST',
async: false,
contentType: 'application/json',
data: data,
dataType: 'json',
processData: false,
success: function(data){
alert('Done')
//Goto Next Page

},

error: function(jqXHR, textStatus, errorThrown){
alert("Some Error!")
}
})

Now on server you can catch this json if u have problem creating json from your text box let me know

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

Comments

1

I often use:

var formData = $("form").serialize();

for posting data over ajax, so maybe you could try:

var textareaData = $(".objectives").serialize();

$.ajax({
    type: "POST",
    url: url,
    dataType: "json",
    data: textareaData
});

or alternatively make sure all the fields are in a form element and use the first example.

Comments

1

You can parameterise it with $.param(objectiveList)

see jQuery.param()

Comments

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.