Uploadify 3.1 settings not working - uploadify

I am sending additional form data along with the file. Here is the form data:
register_object['first_name']=$("#first_name").val();
register_object['last_name']=$("#last_name").val();
register_object['input_email']=$("#input_email").val();
register_object['input_password']=$("#input_password").val();
register_object['repeat_password']=$("#repeat_password").val();
And, following is the uploadify code that I use:
$(document).ready(function(){
$("#image_file").uploadify({
'method' : 'post',
'queueSizeLimit' : 1,
'formData' : JSON.stringify(register_object),
'buttonText' : 'Profile Pic',
'auto' : false,
'multi' : false,
'swf' : 'js/plugins/others/uploadify.swf',
'uploader' : 'upload.ashx',
'fileTypeDesc': 'Image Files',
'fileTypeExts': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
'onUploadStart' : function(file) {
$('#file_upload').uploadify('settings', 'formData', JSON.stringify(register_object));
alert(JSON.stringify(register_object));
},
'onUploadSuccess' : function(file,data) {
alert('The file finished processing. ' + data);
},
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString + ' ' + errorMsg);
}
});
$("#register").submit(function(){
$('#input_password').val(CryptoJS.MD5($('#input_password').val()));
$('#repeat_password').val(CryptoJS.MD5($('#repeat_password').val()));
register_object['first_name']=$("#first_name").val();
register_object['last_name']=$("#last_name").val();
register_object['input_email']=$("#input_email").val();
register_object['input_password']=$("#input_password").val();
register_object['repeat_password']=$("#repeat_password").val();
$("#image_file").uploadify('upload');
return false;
});
});
When I access the post data on the server, I get nothing.
What am I doing wrong?

I was able to finally get the data to the server. Firstly, I had to use $("#image_file") instead of $("#file_upload") (sorry, my mistake) in onUploadStart. And secondly, I had to write complete JSON string within onUploadStart:
$('#image_file').uploadify("settings", "formData", {"first_name":register_object['first_name'],"last_name":register_object['last_name'],"input_email":register_object["input_email"],"input_password":register_object["input_password"],"repeat_password":register_object["repeat_password"]});
The code goes like this:
$(document).ready(function(){
$("#image_file").uploadify({
'method' : 'post',
'queueSizeLimit' : 1,
'formData' : JSON.stringify(register_object),
'buttonText' : 'Profile Pic',
'auto' : false,
'multi' : false,
'swf' : 'js/plugins/others/uploadify.swf',
'uploader' : 'upload.ashx',
'fileTypeDesc': 'Image Files',
'fileTypeExts': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
'onUploadStart' : function(file) {
**$('#image_file').uploadify("settings", "formData", {"first_name":register_object['first_name'],"last_name":register_object['last_name'],"input_email":register_object["input_email"],"input_password":register_object["input_password"],"repeat_password":register_object["repeat_password"]});**
alert(JSON.stringify(register_object));
},
'onUploadSuccess' : function(file,data) {
alert('The file finished processing. ' + data);
},
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString + ' ' + errorMsg);
}
});
....
});

Related

Laravel Datatable Data Display Issue

Below is my controller code. I have seen data in console and network tab ajax call but it is not displaying in view page table. Can someone please help me on this. Please tell me what i am doing wrong in this.
I have checked with static data passed directly on ajax call but also static data is not displaying too. but when i pass any string as static then it will display each character from string in different columns.
$finaldata = array();
foreach($reportDetails as $agentReportColumnKey => $agentReportColumnValue){
$tempfinaldata = array();
$tempfinaldata['Customer Name'] = isset($agentReportColumnValue->name) ? $agentReportColumnValue->name : '-';
$tempfinaldata['Number'] = isset($agentReportColumnValue->tel) ? $agentReportColumnValue->tel : '-';
$tempfinaldata['Email'] = isset($agentReportColumnValue->email) ? $agentReportColumnValue->email : '-';
$tempfinaldata['DOB'] = isset($agentReportColumnValue->signUpQuestionDetails->birthDay) ? $agentReportColumnValue->signUpQuestionDetails->birthDay : '-';
$tempfinaldata['Debt Level'] = $agentReportColumnValue->debtLevel->sum('amountOwned') ? $agentReportColumnValue->debtLevel->sum('amountOwned') : '-';
$tempfinaldata['Total Debt'] = isset($agentReportColumnValue->quickSolution[0]->totalDebts) ? $agentReportColumnValue->quickSolution[0]->totalDebts : '-';
$tempfinaldata['Employment'] = isset($agentReportColumnValue->signUpQuestionDetails->EmpStatus) ? $agentReportColumnValue->signUpQuestionDetails->EmpStatus : '-';
$tempfinaldata['Living Arrangements'] = isset($agentReportColumnValue->signUpQuestionDetails->rentOrOwnHome) ? $agentReportColumnValue->signUpQuestionDetails->rentOrOwnHome : '-';
$tempfinaldata['Downloaded Date'] = isset($agentReportColumnValue->userSignInDate) ? date('d-m-Y', strtotime($agentReportColumnValue->userSignInDate)) : '-';
if(strtolower($agentReportColumnValue->zCaseType) == 'completed') {
$tempfinaldata['Completed Date'] = isset($agentReportColumnValue->userStatusUpdatedDate) ? date('d-m-Y', strtotime($agentReportColumnValue->userStatusUpdatedDate)) : '-';
} else {
$tempfinaldata['Completed Date'] = '-';
}
$tempfinaldata['Case Status'] = isset($agentReportColumnValue->zCaseType) ? $agentReportColumnValue->zCaseType : '-';
$tempfinaldata['Solution Type'] = isset($agentReportColumnValue->UserSolution->solutionType) ? $agentReportColumnValue->UserSolution->solutionType : '-';
$finaldata[] = $tempfinaldata;
}
$totalRecords = UserNames::select('count(*) as allcount')->count();
$totalRecordswithFilter = UserNames::select('count(*) as allcount')->where('name', 'like', '%' .$searchValue . '%')->count();
return [
'aaData' => $finaldata,
"draw" => intval($draw),
"iTotalRecords" => $totalRecords,
"iTotalDisplayRecords" => $totalRecordswithFilter,
];
Below is my view file code.
$('document').ready(function()
{
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type : 'POST',
url : '{{ route('report.full_report_ajax_data') }}',
//dataType: 'json',
cache: false,
success : function(result) {
//pass data to datatable
console.log(result); // just to see I'm getting the correct data.
$('#full_report').DataTable({
"searching": false, //this is disabled because I have a custom search.
//"aaData": [result], //here we get the array data from the ajax call.
"aaData": [result], //here we get the array data from the ajax call.
//"bProcessing": true,
"aoColumns": [
{ "sTitle": "Customer Name" },
{ "sTitle": "Number" },
{ "sTitle": "Email" },
{ "sTitle": "DOB" },
{ "sTitle": "Debt Level" },
{ "sTitle": "Total Debt" },
{ "sTitle": "Employment" },
{ "sTitle": "Living Arrangements" },
{ "sTitle": "Downloaded Date" },
{ "sTitle": "Completed Date" },
{ "sTitle": "Case Status" },
{ "sTitle": "Solution Type" },
] //this isn't necessary unless you want modify the header
//names without changing it in your html code.
//I find it useful tho' to setup the headers this way.
});
}
});
});

Selectize with Ajax call autocomplete and Elastic search on Laravel

i try to make a Facebook Style User search using elastiquent on Laravel 5.5 that autocomplete ad sugest user by typing some char in input field.
The response from Ajax call return correct object but in my js code there is probably somethings wrong.
This the elasticsearch url http://basketmapp.com/users-list?q=Paolo, and in response i can see that item is correctly fetched:
this is the js used for selectize:
$(document).ready(function () {
var topUserSearch = $('.js-user-search');
if (topUserSearch.length) {
topUserSearch.selectize({
persist: false,
maxItems: 2,
valueField: 'name',
labelField: 'name',
searchField: ['name'],
options: [],
render: {
option: function(item, escape) {
return '<div class="inline-items">' +
(item.avatar ? '<div class="author-thumb"><img src="' + escape(item.avatar) + '" alt="avatar"></div>' : '') +
'<div class="notification-event">' +
(item.first_name ? '<span class="h6 notification-friend"></a>' + escape(item.first_name) + '</span>' : '') +
'</div>';
},
item: function(item, escape) {
var label = item.first_name;
return '<div>' +
'<span class="label">' + escape(label) + '</span>' +
'</div>';
}
},
load: function(query, callback)
{
if (!query.length) return callback();
$.ajax
({
url: '/users-list',
type: 'GET',
dataType: 'json',
data:
{
q: query
},
error: function()
{
callback();
},
success: function(res)
{
callback(res.data);
}
});
}
});
}
});
need your help!

Cake PHP div refresh server crashed

I'm using cake php
For 8 times I have used div refresh pattern from the server but after few minutes my server crashed and I have to ask the server provider to reopen the server.
What would be the best way to proceed if I want to use the database through div refresh?
function check()
{
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/rand_f',
dataType : 'html',
data: {},
cache : false,
success:function(result){
$('#ht').html(result);
$("#session_value").val(result);
}});
}
setInterval(check, 1000);
function check_count()
{
var a=$("#session_value").val();
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/check_count/'+a,
dataType : 'html',
data: {},
cache : false,
success:function(result){
if(result=='change'){
$('#res').val(result);
listings_live1();
}else{
$('#res').val('no_change');
}
}});
}
setInterval(check_count, 1000);
function listings_live1()
{
var a=$("#session_value").val();
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/listingsbookingcheck/'+a,
dataType : 'html',
data: {},
cache : false,
success:function(result){
var x= $('#live_listing').html(result);
if(x){
return 1;
}
}});
}
function check_count_all()
{
var x=$("#last_count_all").val();
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/check_count_all',
dataType : 'html',
data: {},
cache : false,
success:function(result){
$("#count_all").val(result);
if(result!=x){
listings_liveall();
$("#last_count_all").val(result);
$("#st").val('change');
}
else{
$("#st").val('nochange');
}
}});
}
setInterval(check_count_all, 1000);
function listings_liveall()
{
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/listingall',
dataType : 'html',
data: {},
cache : false,
success:function(result){
$('#listings_liveall').html(result);
}});
}
function showaction(str,id){
$("#boking_status_call_cancel").show();
$("#alertshow").html('Are you sure you want to '+str+' this Booking?');
if(str!='accept'){
$("#reject_reason").show();
}else{
$("#reject_reason").hide();
}
$("#role_call").val(str+','+id);
}
function update_mobile_booking(){
var strcall=$("#role_call").val();
$.ajax({
type : 'POST',
url : '<?php echo $this->webroot;?>'+'Bookings/update_booking_mobile/'+strcall,
dataType : 'html',
data: {},
cache : false,
success:function(result){
var x=listings_live1();
if(x==1){
listings_liveall();
}
}});
}
/*settimeout page load mobile booking*/
var myFunc = function() {
listings_live1();
listings_liveall();
}
window.onload = function() {
setTimeout(myFunc, 1000);
}
/*
function check_counter_upper(){
c1=$("#session_value").val();
c2=$("#count_chk_cl").val();
if(c1!=c2 && c2!='undefined'){
listings_live1();
$("#st1").val('force_change');
}else{
$("#st1").val('no_force_change');
}
}
setInterval(check_counter_upper, 4000);*/

image not showing in the jsp page after ajax start

My page not showing a gif image while page in ajax request. Its a registration page and while clicking on submit button it should show a spin image and it should disapper after a success
this is my ajax code
$("#register-form").on("submit", function() {
var uname = $('#username').val();
var phone = $('#phone').val();
var mail = $('#email').val();
// $(".loader").show();
$.ajax({
type : "POST",
url : "registerUser",
secureuri : false,
cache : false,
async : false,
data : {
"username" : uname,
"phone" : phone,
"email" : mail
},
success : function(response) {
$(".status").fadeIn("slow");
$(".loader").hide();
$(".status").html(response);
if (response == "Please check your mail to verify account") {
$(".status").css({
"border" : "1px solid green",
"background-color" : "#B2D47F"
});
}
},
error : function() {
alert("error occured");
}
});
return false;
});
here I am binding ajaxstart
$(document).ajaxStart(function() {
$(".loader").show();
});
but it is not showing.. is anything wrong in my code?
Try adding beforeSend and complete handlers to your ajax call, and show/hide the loader in it. This will also work in case of error, because if you are hiding the loader in success handler and error happens, it will stay visible after ajax is completed.
$.ajax({
type : "POST",
url : "registerUser",
secureuri : false,
cache : false,
async : false,
data : {
"username" : uname,
"phone" : phone,
"email" : mail
},
beforeSend : function() {
$(".loader").show();
},
success : function(response) {
...
},
error : function() {
alert("error occured");
},
complete : function() {
$(".loader").hide();
},
});

How to pass extra data to an ajax success event?

How to pass extra data to an ajax success event?
var extra_data = 'some data';
var a = {
type : 'post',
async : true,
cache : false,
dataType : 'json',
timeout : 15000,
contentType : 'application/x-www-form-urlencoded;charset=UTF-8',
global : true,
url : url,
success : [
function(response, textStatus, jqXHR, extra_data){
}
]
};
You can just declare extra_data as a global variable if i remember (without var before) and you can use it inside the scope of the success method, and you don't need to pass it through methods arguments
extra_data = 'some data';
var a = {
type : 'post',
async : true,
cache : false,
dataType : 'json',
timeout : 15000,
contentType : 'application/x-www-form-urlencoded;charset=UTF-8',
global : true,
url : url,
success : [
function(response, textStatus, jqXHR){
console.log(extra_data); //for example
}
]
};

Resources