I am hoping for your help on this one.
I am using Fineuploader and I need to get and send input field value (that will be file group title).
For that I am using path to server side script (I didn't code it thats why I have to do it on my side, somehow):
endpoint: '/Services/hndFileUploader.ashx?case=deals&dealfiletitle=' + $("input").val()
Problem is that DOM with Fineuploader is already loaded and value of input is of course empty.
How can I get dynamic value to send with that query?
Thank you.
You do this using the setParams option for fineuploader. Docs are here, but basically it could be something like:
$('#fineUploaderElementId').fineUploader({
request: {
endpoint: '/Services/hndFileUploader.ashx'
}
}).on('submit', function(event, id, filename) {
$(this).fineUploader('setParams', {'case': 'deals', 'dealfiletitle': $(input).val(); });
});
Related
Can I dynamically edit the url of the datatable depending on the value of the “Value” field of the search form in another file?
For example:
{ view:"text", label:"input data", value:"apple" }
In datatable.js
url: 'resource->/api/archive/apple'
Okay, I was told that I can send AJAX requests, but now I can't figure out how to get them correctly on another page
Sending:
webix.ajax().post('apples', get_form())
routie('apples')
In devtools I get the form value
I'm trying to get the formData value to substitute it in the URL
function get_data() {
let result;
webix.ajax("apples").then(function (data) {
data = data.text();
result = data;
});
return result;
}
URL
url: 'resource->/api/archive/all/'.concat(get_data()),
On the backend side, this controller works well, but I can't call it from the front side. I'm just learning frontend, so any help would be greatly appreciated.
In general, the way to do this is: When the value is changed (the onChange event), call clearAll() and load(newUrl) methods of the datatable. You cannot change the url property at runtime (well, you can, but it won't work).
As for different files, people usually build SPAs with Webix, so files here might be modules, not pages. Do you use Webix Jet? If yes, then communication between the form and the datatable can be done via the app event bus. If not, then they can communicate directly (import both files in some other file and do it there). If this is a multiple-page app, then yes, you do need some server side communication between them (maybe even with sockets).
I'm actually running into little problems with my current project. Following case:
I've got a model called "Posting" with relations:
public function subscribers(){
return $this->belongsToMany('User');
}
In my view-file there is a table containing all Postings and also a checkbox for subscribing/unsubscribing with the matching value to the posting-id:
<input class="click" type="checkbox" name="mobileos" value="{{{$posting->id}}}"
#if($posting->subscribers->find(Auth::User()->id))
checked="checked"
#endif
>
Now the thing I want to archive:
A JavaScript is going to watch if the checkbox is checked or not. According to that, the current user subscribes/unsubscribes to the posting. Something like:
$('.click').on('click',function() {
// $posting->find(---$(this).prop('checked')---)->subscribers()->attach(---Auth::user()->id---);
// $posting->find(---$(this).prop('checked')---)->subscribers()->detach(---Auth::user()->id---);
});
Is there any possibility to archieve that or any other ways? I couldn't get my head around this so far.
Cheers,
Chris
If you want to use Ajax to achieve this, you will need a REST endpoint in Laravel for the subscriptions, e.g.:
http://localhost/subscribe/{{userid}}
When this Endpoint is called, the database can be updated. The function could also return a JSON showing, if the saving database in the database successful.
Use this endpoint to make an Ajax Call on click:
var user = {
id: 0 // retrieve the correct ID from wherever it is stored
}
$('.click').on('click',function() {
$.GET('http://localhost/subscribe/' + user.id,
function () { // this is the success callback, that is called, if the Ajax GET did not return any errors
alert('You are subsribed')
});
});
Ideally you won't be using the GET method, but instead use POST and send the user ID as data. Also you would need to retrieve the user ID from session or wherever it is stored.
Take care that as you are using Ajax it can easily be manipulated from the client side. So on the server you should check, if the user ID that was sent is the same as in the Session. Maybe you don't need to send the user id at all, but that depends on how your backend is built.
We're trying to pass an unique ID into Fineuploader (4.2.2, JQUERY) and reuse that into the fineuploader.js to set the foldername of where the upload is stored.
We basicly found two option:
Set the request option uuidName, which should be a string. Passing this one will result in "null" in console and doesn't do the trick.
Create a params request option where we define a variable with a value.
Option 2 get passed though we've got no idea how we get this value and process it into fineuploader.js (and alter the qq.getUniqueId-function with this new var for example).
Anyone know how we can get this done?
Thanks so much!
EDIT:
Underneath the code which initiates the uploader, how do I get the fileID inside the fineuploader.js?
$(".fine-uploader").fineUploader({
request: {
endpoint: 'server/endpoint',
params: {
fileID: '12345'
}
}
If you would like to override the UUID Fine Uploader creates for a file, you can do so either by passing your new UUID client-side via the setUuid method, or your server can return a newUuid property with its value set to the new UUID in its JSON response.
I have built a calendar in php. It currently can be controlled by GET values from the URL. Now I want the calendar to be managed and displayed using AJAX instead. So that the page not need to be reloaded.
How do I do this best with AJAX? More specifically, I wonder how I do with all GET values? There are quite a few. The only solution I find out is that each link in the calendar must have an onclick-statement to a great many attributes (the GET attributes)? Feels like the wrong way.
Please help me.
Edit: How should this code be changed to work out?
$('a.cal_update').bind("click", function ()
{
event.preventDefault();
update_url = $(this).attr("href");
$.ajax({
type : "GET"
, dataType : 'json'
, url : update_url
, async : false
, success : function(data)
{
$('#calendar').html(data.html);
}
});
return false;
});
Keep the existing links and forms, build on things that work
You have existing views of the data. Keep the same data but add additional views that provide it in a clean data format (such as JSON) instead of a document format (like HTML). Add a query string parameter or HTTP header that you use to decide which view to return.
Use a library (such as YUI 3, jQuery, etc) to bind event handlers to your existing links and forms to override the normal activation functionality and replace it with an Ajax call to the alternative view.
Use pushState to keep your URLs bookmarkable.
You can return a JSON string from the server and handle it with Ajax on the client side.
So that I can send those data using perl/php or any other programmatically.
Say I've a website with a combo box containing 100 cities submitting each city would get me the list of service centers in the city.
So I want to use a perl code where I'd loop all the cities and capture all the results, format them suitably in html for use in my website.
Doing all these using jquery etc will be manual. Also using jquery I'll not be able to catch response in easy way and save it on the hard disk as html file.
im not sure who is sending it where from your description. But i guess that you have an HTML form which sends those data to some PHP script . you specify the PHP in and you catch them on server side using $_POST["variable"]
if you want to send them somewhere else from your php script, use curl http://cz.php.net/manual/en/book.curl.php
This did the trick, I had to learn jquery finally:
var chk = [];
$("#splocator2 #stateid option").each(function() {
chk.push($(this).val());
});
alert(chk.length);
for (i = 0; i < chk.length; ++i){
$("#splocator2").attr("target", "_blank");
$("#stateid option:eq(0)").attr("selected", "selected");
$("#stateid option:eq(0)").attr("value", chk[i]);
$("#splocator2").submit();
}
JavaScript running on a page can not access variables POST'd to it AFAIK.
You may be thinking of sending an XHR to your server side code.
You may use the serialize() method:
$(function() {
$("#myForm").submit(function() {
alert($(this).serialize());
// No thanks I'm gonna use my own post request
// code here!
return false;
});
});
Example.