form-data

is it safe to pass data via ajax?

别说谁变了你拦得住时间么 提交于 2019-12-02 07:45:56
i created script which will count child's div for some certain div with this command $('#content').children().size() by this count i know to fetch from 12 to 18 from mysql if this count is 12. with firebug i can find out this count which will post to my script and i thought is there any way to increase this size to get more details from my database in some way?is it secure to pass such data from ajax? 2-can someone post data or simulate posting in any way?for example simulate data which will post by form like this data=2&foo=3&bar=4 and cheating on server? ATaylor As per my comment, once more

Send XMLHttpRequest with both Header and FormData

醉酒当歌 提交于 2019-12-02 06:39:10
I am trying to send a XMLHttpRequest with a header and add a FormData. Is there an (elegant) way i can do something like this: var formData = new FormData(); formData.append("file", file); var xhr = new XMLHttpRequest(); xhr.open("POST", "/ajax_gateway.php?mod=fileupload", true); xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded") xhr.send(formData, "token=add"); You cannot specify the Content-Type header when sending FormData because that header automatically gets set to "multipart/form-data" by the browser. You can set other headers though, try this: var formData = new

How to append an image from URL to a FormData - Javascript

北慕城南 提交于 2019-12-02 04:08:22
This is my little javascript code: <script> var formData = new FormData(); URL = "view.php?fetchImageById=1"; formData.append("imageFile", ....); formData.append("author","user"); formData.append("description","image"); x=new XMLHttpRequest(); x.open("POST","upload.php",true); x.setRequestHeader("Content-type", "multipart/form-data"); x.setRequestHeader("Content-Length",formData.length); x.send(formData); </script> I don't know how to append the URL to the formData. You could perform two XMLHttpRequest() s; first GET request image as a Blob first by setting responseType to "blob" ; then append

When creating a FormData object from an existing form, are filenames automatically appended and accessible?

自古美人都是妖i 提交于 2019-12-02 03:49:27
Form <form id="my_form"> <input type="file" name="my_file"> <input type="text" name="field_one"> <input type="text" name="field_two"> <button>send</button> </form> Create FormData Object var myFormData = new FormData($("#my_form")[0]); Question Is the filename of my_file accessible even though it hasn't been specifically defined (for DOM manipulation and inserting into database)? This states: You can also append a File or Blob directly to the FormData object, like this: data.append("myfile", myBlob, "filename.txt"); But it doesn't specify whether a filename is automatically added when creating

FormData.get function is undefined

孤人 提交于 2019-12-01 22:16:59
问题 FormData.get is undefined in Chrome https://developer.mozilla.org/en-US/docs/Web/API/FormData/get 回答1: By default, Chrome does not support the .get() method, as well as delete , get , getAll , has , and set . Although you can enable that functionality by activating an experimental flag, note from MDN: [2] Chrome support for methods other than append is currently behind the "Enable Experimental Web Platform Features" flag. For activating flags in Chrome you can go to the following link: chrome

Django Rest Framework: Upload file via AJAX

限于喜欢 提交于 2019-12-01 21:13:08
I have a view and serializer: class UserView(generics.RetrieveUpdateAPIView): model = get_user_model() serializer_class = UserProfileSerializer permission_classes = (permissions.IsAuthenticated,) def get_object(self, *args, **kwargs): return self.request.user class UserImageSerializer(serializers.ModelSerializer): class Meta: model = get_user_model() fields = ('image',) They work great with httpie: http -f put localhost:8000/accounts/api/image/ "Authorization: Token mytoken" image@~/Downloads/test.jpg HTTP/1.0 200 OK Allow: GET, PUT, PATCH, HEAD, OPTIONS Content-Type: application/json Date:

FormData not working in Internet Explorer?

你离开我真会死。 提交于 2019-12-01 20:07:21
function uploadPhoto(file) { if (!file || !file.type.match(/image.*/)){ if(!file){ postStatus(); } else { return; } } var fd = new FormData(); fd.append("image", file); fd.append("privacy", document.getElementById('privacy-handler').value); var xhr = GetXmlHttpRequest(); xhr.open("POST", "url here"); slideUp('photo-upload'); slideDown('photo-manager-txt'); document.getElementById("photo-manager-txt").innerHTML='<i>Please wait a moment while we process your photo.</i>'; xhr.onload = function() { if(xhr.responseText == '0'){ document.getElementById('photo-manager-txt').innerHTML='<br />Photo

POST FormData to php using javascript and XMLHTTPRequest

瘦欲@ 提交于 2019-12-01 13:22:48
问题 At the moment I have two files, index.htm and accessdata.php. This is what I have in index.htm: <html> <head> <script> function postData() { var xmlhttp=new XMLHttpRequest(); var url = "accessdata.php"; var checkBoxes_formData = new FormData(document.getElementById("checkBoxes")); xmlhttp.open("POST",url,true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send(checkBoxes_formData); xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 &&

How do i get the content from a formData?

时光怂恿深爱的人放手 提交于 2019-12-01 05:33:38
I have created a file into the formData like this: var fd = new FormData(); fd.append('file', file); how do i get the content out of the formData? like the filename and the file? something like this?: fd.filename() , fd.getData() . or fd.get('file') to retrieve the file back? mr2k There is no way to retrieve the files after you've appended them in to a formData-object I believe. You'll have to send the formData-object somewhere and then get the files from a req-object or something like that. In my case (angularJS + nodeJS) I tested this from an answer on SO (link below): Angular: var fd = new

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

风流意气都作罢 提交于 2019-12-01 04:03:47
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 follows $data = $_POST['data']; $fileName = $_POST['fileName']; $fp = fopen('/img/'.$fileName, 'w');