Hello,
I am having a problem using the jQuery Form from www.malsup.com. I am using the ajaxForm call as follows:
First, here is my HTML:
- <form id="formID" action="someScript.php" enctype="multipart/form-data">
- <input id="textField" name="textField" type="text" />
- <input id="fileField" name="fileField" type="file" />
- <input id="submitButton" name"submitButton" type="submit" value="submit" />
- </form>
And here is my jQuery:
- $("#formID").ajaxForm ({
- type: "post",
- dataType: "json",
- iframe: true,
- data: {
- additionalDataItem1ToSubmit: "value1",
- additionalDataItem2ToSubmit: "value2",
- arrayToSubmit: someArray // This is the line causing the problem (read below for details)
- },
- beforeSubmit: function () {
- // Do something before making the submit call to someScript.php
- },
- success: function (data) {
- // Do something with the return value (data) from someScript.php
- }
- });
Now, if I comment out line number 8 in the ajaxForm function (arrayToSubmit), everything is fine. However, when this line is commented out and when I try to pass an array as shown in the code, then I get an error and form submission fails (please note that someArray is already initialized, and could either be an empty array or could contain some array items).
The error I receive is:
TypeError: 'undefined' is not a function (evaluating 'this._each(function(value) { iterator.call(context, value, index++); })') I am not sure how to work around it either. All I need is the following requirements.
1. Submit a form via jQuery (preferably using ajaxForm)
2. Use it to upload a file and other input types (such as text)
3. Also submit other information from outside the form, including an array to PHP
4. Run a simple code prior to making the submit
5. Handle a JSON response from PHP in the callback function
As you can see, everything is OK except part of step 3 of the requirements, which is the array.
Please help, and I really really thank you.