Variable in Javascript for uploadify form data is undefined - javascript

Hi I need to save a variable in Javascript and give it to uploadify.
This is my code:
var mediaID;
$(".edit_photo_media").live("click", function() {
mediaID = $(this).data("media-id");
$.ajax({
url: 'edit.php?action=media_select',
type: 'GET',
dataType: 'html',
success: function (select) {
if (select == '3') {
document.location = "login.php";
} else {
$("#dialog_upload_media").dialog("open");
}
}
});
return false;
});
$('#file_upload').uploadify({
'fileTypeDesc' : 'Image Files',
'fileTypeExts' : '*.jpg;',
'fileSizeLimit' : '4096KB',
'debug' : true,
'method' : 'post',
'formData' : {'id' : '' + mediaID},
'swf' : 'include/swf/uploadify.swf',
'uploader' : 'include/scripts/upload_mult.php'
});
So everytime before the uploader is opened .edit_photo_media is clicked.
<img src="images/photo.png" />
This is where the var mediaID is getting its content. Inside .edit_photo_media mediaID is defined correct.
But if I click the upload button mediaID is undefined. Why is the variable loosing its value?
Edit: Ok this seems to be related to a uploadify bug? If I check mediaID on any other function it is working fine... rlly strange

Ok problem solved. Just added 'onUploadStart' and saved the id in there
$('#file_upload').uploadify({
'fileTypeDesc' : 'Image Files',
'fileTypeExts' : '*.jpg;',
'fileSizeLimit' : '4096KB',
'buttonText' : 'Bilder auswählen',
'debug' : true,
'method' : 'post',
'formData' : {'id' : 0},
'swf' : 'include/swf/uploadify.swf',
'uploader' : 'include/scripts/upload_mult.php',
'onUploadStart' : function(file) {
$('#file_upload').uploadify("settings", "formData", {"id": mediaID});
}
});

jQuery only started subsuming HTML5 data properties set in the source code from version 1.6 onwards. If you're using < 1.6, this won't happen, in which case upgrade jQ.

Related

Add dynamic input field in ajax

Is there a way to put a dynamic input inside ajax? I am using hayageek jquery file upload. I wanted to add an input as hidden inside the form upload for replacing a file. Any help would be much appreciated.
The div that handles upload:
<div id="replacefile">Upload</div>
I wanted to put: <input type="text" name="replace">
$("#replacefile").uploadFile({
url : newurl,
fileName : "myfile",
returnType : "json",
dragDrop : true,
showFileCounter: false, // show numbered list of file
allowDuplicates: false,
multiple : true, //allow multiple file upload
showFileSize : false, // show file size
acceptFiles : "doc,pdf",
onSuccess : function(files,data,xhr,pd) {
// success
},
onError : function() {
// error
}
});
$("#replacefile").uploadFile({
url : newurl,
fileName : "myfile",
returnType : "json",
dragDrop : true,
showFileCounter: false, // show numbered list of file
allowDuplicates: false,
multiple : true, //allow multiple file upload
showFileSize : false, // show file size
acceptFiles : "doc,pdf",
onSuccess : function(files,data,xhr,pd) {
// success
var input=$('<input type="text" name="replace">');
$('#replacefile').find('form').append(input);
},
onError : function() {
// error
}
});

Load ajax success data on new page

My ajax call hits the controller and fetches a complete JSP page on success. I was trying to load that data independently on a new page rather than within some element of the existing page. I tried loading it for an html tag but that didn't work either. I tried skipping the success function but it remained on the same page without success data. My ajax call is made on clicking a normal button in the form and the code looks like as shown below.
$.ajax({
url : '/newpage',
type : 'POST',
data : requestString,
dataType : "text",
processData : false,
contentType : false,
success : function(completeHtmlPage) {
alert("Success");
$("#html").load(completeHtmlPage);
},
error : function() {
alert("error in loading");
}
});
This should do:
$.ajax({
url : '/newpage',
type : 'POST',
data : requestString,
dataType : "text",
processData : false,
contentType : false,
success : function(completeHtmlPage) {
alert("Success");
$("html").empty();
$("html").append(completeHtmlPage);
},
error : function() {
alert("error in loading");
}
});
You can try this,
my_window = window.open("");
my_window.document.write(completeHtmlPage);
into your success.

Load fancybox when ajax returns ERROR

Here is the scenario:
My AJAX script determines whether or not a user is logged in when he clicks on an action.
When the user is not logged in, AJAX returns error. I want to load div which contains login form on a fancybox.
How can I do this?
Here is what I have:
$.ajax({
type : 'POST',
url : 'xyz.action',
dataType : 'text',
herf :'login.jsp',
success : function (data) {},
error : function () {
alert("PLEASE LOGIN");
$("#loginForm").fancybox({
'width' : '75%',
'height' : '75%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe'
});
}
});
return false;
Login
I got the solution :)...
$("#fan").fancybox({
'enableEscapeButton' :true,
'type':"iframe",
href :'login.jsp',
'hideOnOverlayClick' : true
}).trigger('click');
Try
$.fancybox('login.jsp');
If that doesn't work, I like to do this:
$.post('login.jsp',function(data){$.fancybox(data);});

How to read extra properties from model store EXTJs?

​Json reader in is defined for the store as follows:
Ext.define('App.store.MyList', {
extend : 'Ext.data.Store',
model : 'App.model.MyList',
pageSize : 100,
proxy : {
type : 'ajax',
actionMethods : {
create : 'POST',
read : 'POST',
update : 'POST',
destroy : 'POST'
},
root : 'results',
url : 'aaa.htm',
reader : {
type : 'json',
root : 'results',
totalProperty: 'totalCount',
extraProperty: 'abcd'
},
simpleSortMode : true
}
});
How do I read extra property outside the root? I tried to put one inside the reader, it did not work.
try this
grid.getStore().getProxy().getReader().extraProperty

Uploadify error with Internet Explorer 9

Hi I am trying to use JQuery Uploadify plugin using the following code:
$('input#uploadFile_CSV').uploadify({
'uploader' : '/images/uploadify.swf',
'cancelImg' : '/images/cancel.png',
'script' : 'RequestController',
'buttonText': 'Import CSV',
'scriptData': {'command': 'ImportCSVFileCommand',
'workspaceId': $.workspaceGlobalInformation.id},
'method' : 'GET',
'auto': true,
'onComplete' : function(event, ID, fileObj, response, data) {
resetCSVDialogOptions();
showCSVImportOptions(response);
}
});
I keep getting a HTTP error and I can't read my script data at the server end. Any help would be appreciated. Thanks.

Categories

Resources