how to send file data using Dajaxice? - ajax

I am using ajax for my website. I have successfully used jQuery.ajax() to asynchronously upload file to server. I am using Dajax and Dajaxice therefore I plan to use these application for file upload as well. I tried this example. It is working fine. But if I add file field into my html form, it does not send file to server. My html form looks like
<form id="myform" action="/file/" method="post" enctype="multipart/form-data">
<div style='display:none'><input type='hidden' name='csrfmiddlewaretoken' value='AaSmyBEwQLSD3YghRAD9Cf2uxEjzESUe' /></div>
<p><label for="id_docfile">Select a file</label> max. 42 megabytes</p>
<p><input type="file" name="docfile" id="id_docfile" /></p>
<p><input type="submit" value="Upload" /></p>
</form>
This question has been asked at many place but never answered.

Afaik there is currently no provision within dajax / dajaxice to upload files.
I have used dajax in a few projects and have got round this by using blueimp/jquery-file-upload and a django view that accepts a POST of the upload file and return a JSON string to the client.
This is a less than perfect solution not least because the jquery-file-upload button is styled differently from normal html form elements, it is possible to style the whole form using jQuery-ui, although this is a lot of additional work.
Both, dwr which is pretty much dajax for Java, and tasty pie for django do offer file uploading, so in theory it should be possible to implement it.
I'm happy to post a sample of my ajax solution if anyone would find them useful.

I've also faced this problem recently. So, I've digged a little and discovered some answers.
It is working fine. But if I add file field into my html form, it does not send file to server.
There's serialize() method used in the doc example. But according to the jQuery doc:
Data from file select elements is not serialized.
Also, there's no clear way to get ajax file upload, because JS doesn't have access to the outside of the client browser. So, I don't think it's possible to make using dajaxice.
The easiest hack, I've found is to post form to the invisible iframe using target option:
<form method='POST' action='/upload' enctype='multipart/form-data' target='submit-iframe'>
so, only the iframe will be refreshed. Using js you than can get data from it catching the load() event.
More detailed process described here

Related

Oracle Apex to receive form submit POST data

I am new to Oracle Apex.I am trying to receive POST data in Oracle Apex page. I want to submit a HTML form and receive that post submission in my Oracle Apex app. searched web but couldn't get suggestions.
In my Oracle database 11g, I have configured Apex 18.1 which is running in 8085 port and created some basic pages.
<!DOCTYPE html>
<html>
<body>
<h2>HTML Forms</h2>
<form action="http://localhost:8085/apex/f?p=106:4:9735956410807:::::" method="post">
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John"><br>
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to Oracle Apex page.".</p>
</body>
</html>
This POST submission will be from external source and Apex app should process this submission.
Thanks in advance.
There are a couple options here:
You could create a webservice using APEX Restful services and sending there. It's probably much safer than exposing you application like you are doing. Worst case scenario you'll have to convert you form post to a json on the backend of the original app, which should be easy pease.
Why not just create a public page with an APEX form and execute a process after the submit happens? You have a tool that generate forms and you are building one from scratch?
*** Having said that, you might want to have the page in a different domain, site, etc... I still think you would be better telling on the other site that the person would be redirected and then sending it to the APEX form

Is it possible to save form data through with Vue.js through Controller without Axios or asynchronous call?

I have a function in my controller that is used to store data. I am recreating my front end using Vue.js. As of now, I removed the current Laravel {{ Form: }} with Vue.js. Can I use same synchronous route without api to post the data? APIs are not ready and I cannot wait to validate my forms
Sure you can, all you need to do is to be aware that HTML does not have methods other than GET and POST. So, if you have PUT, DELETE and others, you're going to have to use the _method param trick.So, for example, when using the PUT http verb, you should create your form something like this:
<form method='POST'>
yourfields...
<input type="hidden" name="_method" value="PUT">
</form>
Other than that, it's pretty much calling the correct endpoints from your Vue application.

Ajax calls without AjaxHelper in aspnet core 2

I was trying to implement an asynchronous call with ajax in my aspnet core 2.0 project, using "Ajax.BeginForm", but then I discovered according to these threads on github and stackoverflow that there's no support to this class in aspnet core, nor MVC 6.
Is there any other way to use ajax assynchronous calls, in aspnet core, besides the old way, with $.ajax function? My problem with this, is that, with AjaxHelper class, I could do everything with razor, in the view file, and keeping everything organized in one place.
Why would i use the razor language to make a loop, and print a list, or whatever, if i have to to make the ajax call, in the js file (or in a < script > tag)? I could work with the data right there, with js, and keep everything there!
How are you guys solving this right now? Thanks for your help.
This baffled me a bit too. I was like where is my lovely #Ajax helper that saved me allot of time in JS hell.
As #sam linked they have changed the API to be more HTML 5 semantic - Not sure why but OK
<form asp-controller="Home" asp-action="SaveForm"
data-ajax-begin="onBegin" data-ajax-complete="onComplete"
data-ajax-failure="onFailed" data-ajax-success="onSuccess"
data-ajax="true" data-ajax-method="POST">
<input type="submit" value="Save" class="btn btn-primary" />
<div id="Results"></div>
</form>
You can also do the same on anchors and don't forgot the tag to enable it
<a data-ajax="true" data-ajax-begin="alert('Hello!')">TEST</a>
And then I suppose you could create TypeScript files per page similar to Angular or one TypeScript per site, or just put the script on the page, example
var onSuccess = function(context){
alert(context);
};

AntiSamy is not allowing me to input form fields

I have a RichTextArea from CKEditor. And I recently made some changes to sanitize HTML input.
Normal things go through fine but any form fields like checkboxes, textareas, radio buttons etc are stripped out.(I am using getValidSafeHTML to sanitize my HTML).
I have tried different policy files like this thing here which is supposed to allow everything
http://code.google.com/p/owaspantisamy/downloads/detail?name=antisamy-anythinggoes-1.4.4.xml
For example,
<form method="get" name="sampleform"><input name="radio" type="radio" /> </form>
becomes
<form method="get" name="sampleform"> </form>
Anybody have any idea why this is happening?
Thanks in advance
I just found the reason why this is happening... I was using the antisamy-1.3.jar. This looks like a bug in this version of antisamy. I needed to upgrade to antisamy-1.5.3.
So just check the versions of your antisamy jars. You might be facing the same issue

Cant download PDF with Ajax response (headers are ignored)

Im trying to download a pdf with ajax request yet the response from that request ignores my "Content-Type:application/pdf" header.
The ajax request
return Superagent.post(url, data).use(this._addDefaults.bind(this));
The symfony response
return new BinaryFileResponse($target);
Workaround
open in new tab and put a direct url for the file.
I think this is similar to a problem I've encountered in the past. Issue is that browsers don't open responses to POST ajax requests by default. I ended up resorting to the automatic form posting instead. In the HTML:
<form method="post" action="http://handler1.ashx" target="_blank">
<input type="hidden" id="data" name="data" value="post_body_stuff"/>
<button id="pdfsubmit" type="submit" value="Submit">Export to PDF</button>
</form>
You can use javascript to put all the data you want to POST as the value on the hidden input field instead of post_body_stuff. This way, when the content comes back the browser will try to open or save it as a file rather than read it as response text.

Resources