form-data

How to append datetime value to formdata and receive it in controller

微笑、不失礼 提交于 2019-12-01 02:09:15
问题 I want to know how I can pass datetime value through formdata and retrieve it in controller and convert it to DateTime in the controller I've tried as below: var formdata=new FormData(); fromDate = $('.from_date').datepicker('getUTCDate'); toDate = $('.to_date').datepicker('getUTCDate'); formdata.append("start", new Date(fromDate)); formdata.append("end", new Date(toDate)); and in $.ajax I am setting data:formdata in my controller I receive it as below: DateTime frmDate = Convert.ToDateTime

Ajax POST request via jQuery and FormData - $_POST empty on PHP

天大地大妈咪最大 提交于 2019-12-01 01:47:04
问题 I wish to upload an image to the server via ajax using jQuery and FormData. My jQuery code is as follows var formData = new FormData("form")[0]; var fileName = $("#InputLogo")[0].files[0].name; $.ajax ( { url : 'upload.php', type : 'POST', data : { "data" : formData, "fileName" : fileName }, processData : false, success : function(data) { console.log(data); alert(data); } }); This code is called when the user selects a new file to upload. MY server backend is PHP and it handles the request as

How to send files with superagent

你。 提交于 2019-11-30 18:11:00
问题 So about a month ago I asked a question regarding superagent and sending files, but got no response at all. I would still like to find out how to do this as I enjoy using superagent. I am able to send files using plain ajax: var fd = new FormData(); fd.append( 'file', this.refs.File.getDOMNode().files[0] ); $.ajax({ url: 'http://localhost:8080/files', data: fd, processData: false, contentType: false, type: 'POST', success: function(data){ console.log(data) } }); But when I try the same thing

FormData in IE 11 not defined

﹥>﹥吖頭↗ 提交于 2019-11-30 17:52:59
问题 I have the following script to get the file data from a input type of file: var uploadfiles = $("#upFile").get(0); var uploadedfiles = uploadfiles.files; var fromdata = new FormData(); for (var i = 0; i < uploadedfiles.length; i++) { fromdata.append(uploadedfiles[i].name, uploadedfiles[i]); } // ajax code omitted that uploads file This works great in all browsers I have tested with, except IE 11. In this it doesn't understand what FormData() is?? I have read quite a few different workarounds

Testing Form posts through MockMVC

让人想犯罪 __ 提交于 2019-11-30 17:15:25
I'm writing tests to verify that I can do a generic form post to our API. I've also added quite some debugging, but I noticed that the data posted by an actual form; (Postman / AngularJS or w/e) Differs from doing a mockMVC test like: MvcResult response = mockMvc .perform(post("/some/super/secret/url") // .param("someparam1", "somevalue") // .param("someparam2", "somevalue") // .contentType(MediaType.APPLICATION_FORM_URLENCODED) // .accept(MediaType.APPLICATION_JSON)) // .andExpect(status().isOk()) // .andReturn(); The config is exactly the same as the config running in production, and such.

HTML5 FormData returns null in Java Servlet request.getParameter()

流过昼夜 提交于 2019-11-30 13:53:48
My view is HTML 5. I'm using FormData to make a AJAX 2 POST to a Servlet. Inside the servlet i'm trying to read request parameters. I can't see any parameters. However, Google Chrome Dev console shows the request payload. How can I get the same in Servlet code? Any help will be appreciated. Here's the code. JS code var xhr = new XMLHttpRequest(); var formData = new FormData(); formData.append('firstName', 'ABC'); formData.append('lastName', 'XYZ'); xhr.open("POST", targetLocation, true); xhr.send(formData); Servlet code (both parameters return null ) out.println("Hello! "+ request.getParameter

Why are HTML forms sometimes cleared when clicking on the browser back button

China☆狼群 提交于 2019-11-30 05:02:36
I am sure everybody knows that behaviour. You fill in a form on the web, and you submit it. After the submission you recognize that you filled in some wrong data. So, you click on the browsers back button. Then, sometimes the form still have the data you entered (what you are hoping in this situation) and sometimes not. I couldn't find any connection when it is cleared and when not. Some answers i found on the internet / stackoverflow: on https connections, forms are always cleared when using dynamic websites with sessions, forms are always cleared But both of them are definatly wrong. I have

Upload a base64 encoded image using FormData?

天涯浪子 提交于 2019-11-29 18:55:58
问题 I have a jpeg as a base64 encoded string. var image = "/9j/4AAQSkZJRgABAQEAS..." I would like to upload this jpeg to the server using FormData. var data = new FormData(); What is the proper way to append the image to data? 回答1: Your image data is nothing more than a string, so append it to your FormData object like this: data.append("image_data", image); Then on your server side you can store that directly in a database or convert it to an image and store it on the file system. You might find

parsing a formdata object with javascript

蓝咒 提交于 2019-11-29 16:54:38
My company uses a propitiatory application server in which the server side programs are written in javascript (not node.js) . This is a very initial thing and support isn't that good Now here is my problem : I am having to process an uploaded csv on the server side .. I am using the super answer at How can I upload files asynchronously? (passing the formdata object with jquery) and i am able to access the sent file on the server side . But how do i parse it out ? It looks like this ------WebKitFormBoundaryU5rJUDxGnj15hIGW Content-Disposition: form-data; name="fileToUpload"; filename="test.csv"

Testing Form posts through MockMVC

早过忘川 提交于 2019-11-29 11:02:14
问题 I'm writing tests to verify that I can do a generic form post to our API. I've also added quite some debugging, but I noticed that the data posted by an actual form; (Postman / AngularJS or w/e) Differs from doing a mockMVC test like: MvcResult response = mockMvc .perform(post("/some/super/secret/url") // .param("someparam1", "somevalue") // .param("someparam2", "somevalue") // .contentType(MediaType.APPLICATION_FORM_URLENCODED) // .accept(MediaType.APPLICATION_JSON)) // .andExpect(status()