laravel-excel: How to use progress bar when exporting - laravel

Now my download is ok. I think use a progress bar is better. I see this: https://docs.laravel-excel.com/3.1/imports/progress-bar.html
But it's for imports. And I want to use in blade, ajax. Can someone give me some suggestion?
<script type="text/javascript"><!--
$('#button-export-save').on('click', function () {
var dataString = $('#excel-form').serialize();
$.ajax
({
type: "POST",
url: "{{ route('lang.admin.member.members.export') }}",
data: dataString,
cache: false,
xhrFields:{
responseType: 'blob'
},
success: function(data)
{
var link = document.createElement('a');
link.href = window.URL.createObjectURL(data);
link.click();
},
fail: function(data) {
alert('Not downloaded');
}
});
});
//--></script>

Related

laravel - ajax formdata wont show in controller

I have tried many different combination for AJAX Setup in order to send the formData to controller. Somehow I cannot get the form input inside my controller despite trying to return it will all type of ways. May I know what did I miss that causing me not be able to get the input in controller?
$("#formCropUpdate").on("submit", function (event) {
event.preventDefault();
var formId = $('#formId').val();
var url = '/Form/' + formId;
var form = this;
formData = new FormData(form);
console.log(Array.from(formData));
$.ajax({
url: url,
type: "PATCH",
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
cache: false,
dataType: false,
contentType: false,
processData: false,
data:formData,
success: function (response) {
console.log(response);
return false;
},
});
});
public function update(Request $request){
$UserId = Auth::user()->id;
$Company = Company::where('id', Auth::user()->company_id)->first();
return $request->all();
}
use
<meta name="csrf-token" content="{{ csrf_token() }}">
in head
and jQuery code
$('#form_submit').submit(function (e) {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
e.preventDefault();
var base = window.location.origin;
let formData = new FormData(this);
let my_url = base + "/article-store";
$.ajax({
type: 'post',
url: my_url,
data: formData,
cache: false,
contentType: false,
processData: false,
success: (data) => {
},
error: function (data) {
}
});
});
After quite a bit of digging, since what I am doing is using the PATCH request, it's still not working as of now with FormData. To solve it, we need to spoof the method by appending the PATCH method to formData and our AJAX settings to be changed to POST. Then you'll receive all the request inside your controller.
Reference:
https://laracasts.com/discuss/channels/laravel/ajax-formdata-and-put-fails
https://laracasts.com/discuss/channels/javascript/axiosajax-http-patch-requests-with-file-not-working
$("#formCropUpdate").on("submit", function (event) {
event.preventDefault();
var formId = $('#formId').val();
var url = '/Form/' + formId;
var form = this;
formData = new FormData(form);
formData.append('_method', 'PATCH');
console.log(Array.from(formData));
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: url,
data:formData,
cache: false,
contentType: false,
processData: false,
success: function (response) {
console.log(response);
return false;
},
});
});

Can't post ajax value

Still stack in these code. On any browser desktop working fine, but when try use chrome on my android, can't post value from ajax datastring.
jQuery(document).ready(function()
{
jQuery(".button").click(function()
{
var product = jQuery(".products").val().split('|')[0];
var nomortujuan = jQuery(".nomortujuan").val();
var pn = parseFloat(document.getElementById("val[pin]").value);
var dataString = 'method=sendMessage&message='+product+'.'+ nomortujuan+'.'+pn;
var web = 'ajax.php';
jQuery.ajax ({
type: "POST",
url: web,
data: dataString,
cache: true,
beforeSend: function(html) {
document.getElementById("hasil").innerHTML = '';
jQuery(".flash").show();
jQuery(".flash").html('<div style="float:left;"></div>');
},
success: function(html){
jQuery("#js_process_request input, #js_process_request select").attr('disabled',false);
jQuery(".flash").hide();
jQuery("#hasil").hide();
jQuery ("#hasil").append(html);
return false;
}
});
});
});
Maybe this problem
jQuery ("#hasil").append(html);
remove spacing to fix it
jQuery("#hasil").append(html);

Ajax Post integer not posting error

<script>
$(document).ready(function () {
$("#MyForm").click(function () {
var dd = JSON.stringify({
Id: $("#CustomerId").val(),
name: $("#Name").val(),
gender: $("input:checked").val(),
mobile: $("#Mobile").val(),
adress: $("#Adress").val()
});
alert("hi");
$.ajax({
url: '/Cust/Create',
type: 'POST',
contentType: "application/json",
dataType: 'json',
data: JSON.stringify(dd),
success: function (data) {
alert("Data sent to store:" + data);
},
error: function () {
alert("failed in posting");
}
})
});
});
</script>
Iam not able to get the values of the CustomerId and Mobile where as iam getting null values over to the controller can anybody give some suggestion
Thanks in advance.

AJAX Crashes Chrome

Umm.. my problem is that i want to use ajax for my chatbox but whenever i try to put ajax for no-reload refresh Chrome/Firefox Crashes down.. HERE's my code:
/chatlog.php/
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
//<script src="https://ajax.googleapis.com/ajax/libs/mootools/1.3.0/mootools.js"></script>
<script>
var auto_refresh = setInterval(
function()
{
$.ajaxSetup({ datatype: "html" });
$('#loaddiv').load('chatlog.php');
}, 10000);
</script>
/submit.php/
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$(".submit").click(function(){
var message = $("#message").val();
var dataString = 'message'+message;
$.ajax({
type: "POST",
url: "submit.php",
data: dataString,
async: false,
});
/*$message=$_POST['message'];
$name = $_SESSION['username'];
$room = $_SESSION['room'];
$user = $_SESSION['user'];*/
});
});
</script>
$.ajax({
type: "POST",
url: "submit.php",
data: { message : message },
async: false
});
Also put your ajaxSetup outside of the setInterval function.
$.ajaxSetup({ datatype: "html" });
Pass your data properly, like:
var dataString = 'message'+message;
//Should Be
var dataString = 'message='+message;
//OR
var dataString = {'message' : message };

Facebook Subscribe Call Back

Facebook subscribe didn't call back. How callback successful?
<script> window.fbAsyncInit = function() {
FB.init({status: true, cookie: true, xfbml: true}); var user= "<?
echo $data->id;?>";
document.getElementById("Hint").style.display='block';
FB.Event.subscribe('edge.create', function(response) {
$.ajax({
type: "POST",
url: "fbareceive.php",
data: "data="+response + "---" + user,
cache: false
});
(function() { var e = document.createElement('script'); e.type =
'text/javascript'; e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js'; e.async = true;
document.getElementById('fb-root').appendChild(e); }());
</script>
$.ajax() is a jQuery function. Please read the relevant documentation: http://api.jquery.com/jQuery.ajax/
Briefly:
$.ajax({
type: "POST",
url: "fbareceive.php",
data: "data="+response + "---" + user,
cache: false,
success: function(){
alert('Success');
}
});

Resources