Uploadify formData not coming over - uploadify

I'm trying to implement Uploadify into a classic ASP application. The values I'm passing in the settings formData are not available in upload.asp. I've tried putting formData in it's own option field and that isn't working either.
Funny part is that I can 'see' it in Fiddler...so I'm not sure what the heck is going on.
Below is my uploadify code. In upload.asp a call to request.form("sellerid") is blank.
Any ideas?
<script type="text/javascript">
$(function() {
$("#file_upload").uploadify({
'method' : 'post',
'swf' : 'uploadify.swf',
'uploader' : 'upload.asp',
'onUploadStart' : function(file) {
$("#file_upload").uploadify("settings", "formData",
{ "sellerid" : "999", "sellerloginid" : "joeseller" }
);
}
});
});
</script>

Related

Vue JS Ajax Calls

I am trying to make the change from jQuery to Vue.js and am having some difficulty running an Ajax Call using vueresource. Below is a sample script I am using, with both jQuery and Vuejs. Both trying to access the same ajax call. The jQuery call works, the vuejs call doesn't. The sendAjax method is being called because the first 2 alerts show - then nothing.
Edit - this is only causing an error while running the Ajax call through Wordpress. Outside of WP, it does work. Any ideas??
<!DOCTYPE html>
<html>
<head>
<title>Vue Resource</title>
<script src="https://cdn.jsdelivr.net/npm/jquery#3.2.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/vue/latest/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue-resource#1.5.1"></script>
</head>
<body>
<button id="jQueryAjax">Jquery AJAX</button>
<div id="myvue">
<button #click.prevent="sendAjax()">AJAX</button>
</div>
<script>
let AjaxUrl = "http://localhost:8888/mySite/wp-admin/admin-ajax.php";
const postData = { action: 'my_ajaxcall', function: 'AjaxTest' };
Vue.use(VueResource);
const ajax_app = new Vue({
el: '#myvue',
methods: {
sendAjax() {
alert("VueAjax");
alert(JSON.stringify(postData));
this.$http.post(AjaxUrl, postData).then(res => {
alert(JSON.stringify(res));
});
}
}
});
$("#jQueryAjax").click(function() {
alert("jQueryAjax");
alert(JSON.stringify(postData));
alert(AjaxUrl);
$.ajax({
type: 'POST',
url: AjaxUrl,
data: postData,
dataType: 'json',
success: function(data) {
alert(JSON.stringify(data));
},
error: function (xhr, ajaxOptions, thrownError) {
alert("Error");
}
});
});
</script>
</body>
</html>
You AJAX call probably encounters an error and you handle only the successful calls. Please extend your sendAjax function like this:
this.$http.post(AjaxUrl, postData).then(res => {
alert(JSON.stringify(res));
}, err => {
alert(err);
});
Now an error should be alerted.
BTW: It is better to use console.log() instead of alert(), it is much more readable and you won't have to confirm every alert.
After #mbuechmann pointing me to be able to see the actual error, I was able to determine that the issue I was having was actually to do with Wordpress. In order to use the Wordpress Ajax handler, you need to send an action to the REQUEST header. To do this, you need to send FormData, and without sending headers.
This code was found in this question : Custom Shortcode AJAX 400 Bad Request and enabled me to get my Fetch working with Wordpress.
var data = new FormData();
data.append( 'action', 'aj_ajax_demo' ); data.append( 'nonce', aj_ajax_demo.aj_demo_nonce );
fetch(aj_ajax_demo.ajax_url, {
method: 'POST',
body: data, }).then(response => {
if (response.ok) {
response.json().then(response => {
console.log(response);
});
} });

why ajax in an external js file is not working in codeigniter framework

I am created a external js file for plotting a graph in codeigniter. My controller is reached in js file. but the ajax in that file is not supported. here i am attaching the ajax code.`
$(document).ready(function () {
var baseurl = "<?php echo base_url(); ?>";
$.ajax({
url : baseurl + "Welcome/pidiagram",
type : "GET",
success : function (data) {
alert("data");
console.log(data);
}
)};
});
the control is reached inside the document ready function but not inside the ajax.
so please help me.....
most likely your js File won't get parsed by PHP since you outsourced it in an own file
the only thing i'd suggest here is, to add your base URL as an attribute to the html tag e.g.
<html data-base-url="<?php echo base_url(); ?>">
and after that its pretty simple
$(document).ready(function ()
{
var baseurl = $('html').attr('data-base-url');
$.ajax({
url : baseurl + "Welcome/pidiagram",
type : "GET",
success : function (data) {
alert("data");
console.log(data);
}
)};
});

Cache content loaded via AJAX in Fancybox

Due to performance optimization I want to prevent users from reload fancyboxes they already loaded once. This is my code:
$(document).ready(function() {
$(".fancybox-effects").fancybox({
type : 'ajax',
wrapCSS : 'fancybox-custom'
});
});
Adding this:
$.ajaxSetup({ cache: true });
to the document.ready function doesn't help. Any ideas?
You could try
$(document).ready(function() {
$(".fancybox-effects").fancybox({
type : 'ajax',
ajax : { cache: true },
wrapCSS : 'fancybox-custom'
});
});

Web service not called the second time if i make a request to webserver

I have an application made by using phonegap 1.5.0 and jquery mobile 1.1.0....
I have a structure like this
<div data-role="page" id="page1">
</div>
<div data-role="page" id="page2">
</div>
I call a webservice on page show of the page2 like this
$("#page2").on("pageshow", function(e) {
$
.ajax({
type : 'GET',
url : "http://192.168.1.88:9051/some.xml"
+ "?time=" + Date.now(),
data : {
key : "value"
},
dataType : "xml",
success : function(xml) {
},
error : function(xhr) {
alert("Error while loading the Mock Service !!!");
}
});
});
This works fine if i enter for the first time to Page2. Suppose if i navigate back to page1 and then again to Page2 then the webservice isnt called.
I even tried with pageinit and it didnt worked... Is this some Ajax issue?
How to rectify this?
Have you tried turning off caching?
// setup globally
$.ajaxSetup ({
cache: false
});
Or,
// setup individual calls
$.ajax({
cache: false, // disable caching
type : 'GET',
url : "http://192.168.1.88:9051/some.xml"
+ "?time=" + Date.now(),
data : { key : "value"},
dataType : "xml",
success : function(xml) {
},
error : function(xhr) {
alert("Error while loading the Mock Service !!!");
}
});
});
did you check with firebug, the "Console" and the "Net" tab to see what your script sends and receives?
$("#div")
looks wrong to me. should be either div (all div elemets) or #page1 (id 'page1')

Validation uploadify

I am using jQuery Uploadify to upload files to my site. How can I tell if a user has selected a file or not? I tried using the folder object value of the Uploadify object
but its not working for me--it's always the same. I assume that it was null before it was selected.
How can I tell that a user has selected a file?
You could try something like this:
<script type="text/javascript">
var selected = false;
$(document).ready(function() {
$('#fileInput').uploadify({
'uploader' : 'uploadify.swf',
'script' : 'uploadify.php',
'cancelImg' : 'cancel.png',
'auto' : true,
'folder' : '/uploads',
'onSelect' : function() { selected = true; },
'onCancel' : function() { selected = false; }
});
});
</script>
Then you can test if 'selected' is true/false.

Resources