Open file upload dialog after Ajax post success - javascript

I have functionality in which it is required to open file upload dialog after Ajax call success event.
What I tried:
I tried applying below simple code in ajax success: and complete: event but it is not working.
$.ajax({
url: url,
type: 'GET',
dataType: 'json',
data: { id: eoid },
contentType: 'application/json; charset=utf-8',
success: function (data) {
// some logic
$("#fileupload").click();
}
});
What is problem:
If I put simple button and try to execute above code, it is working fine and opening dialog - but it is not working in case of ajax post afterwards.
Any guesses or am I missing something?
Thank you.

The problem is at dataType: 'json' . You are loading html with your ajax request so you should change it to dataType: 'html' else in any other format it will not be considered success. Or you can delete this property as stated in Jquery doc that Jquery does default: Intelligent Guess (xml, json, script, or html).

Related

Not able to get data that is in Bengali language from server using jQuery AJAX

I am not able to get data that is in Bengali language from server using ajax. The data from server is getting replaced by something I don't know. But if I normally set the data means not using ajax, data is getting displayed properly. My code is:
<meta content="html/text" charset="UTF-8"> in .jsp file
$.ajax({
url: "",
data: "a=a",
contentType: "charset=utf-8",
method: "get",
success:function(){
},
failure:function(){
}
});
I have taken reference from UTF8 encoding not working when using ajax, but even this did not work.
The error is in the ajax statement config.
contentType="charset=utf-8",
Here, you should use : instead of =.
See the error highlighted in the code below.
$.ajax({
url: "YOUR URL HERE?myparam1=value1&param2=value2",
data: "a=a",
contentType: "charset=utf-8",
// ^
method: "GET",
success: function(resp) {},
failure: function(err) {}
});

Ajax cross domain POST in IE8 and IE9

I am trying to make a ajax cross domain POST in IE9 and IE8 to a rest endpoint that resets a password and am not having any luck. The ajax call I am trying to make is as follows:
$.ajax({
type: 'POST',
crossDomain: true,
url: postUrl,
contentType: 'application/json; charset=utf-8',
data:{ "userid":uid, "email":email, "password":password },
dataType: 'jsonp',
success: function (data) {
console.log(data);
},
error: function (status){
console.log(status);
}
});
I am also making sure to include the following before the POST call:
$.support.cors = true;
Everytime I make the call it goes into the error function. It says the status is success however when I try to login with the new password it is not working which means it wasnt a success. The following is the response that I output to the log:
[object Object]{readyState: 4, status: 200, statusText: "success"}
Also note that I am calling the jQuery.XDomainRequest.js by MoonScript. That several other stack overflow answers say to do. And my jquery version is 1.11.3
Can someone please provide me some direction on this.

Ajax request inside ajax request with Laravel

I have a code that works like this:
$.ajax({
type: "POST",
url: url,
data: formData,
cache: false,
processData: false,
contentType: false,
dataType: 'html',
This loads:
Route::post('/local/pdf', 'LocalController#subirPDF');
Which loads the controller:
return View::make(Config::get('rv.paginasPDF'));
Which loads:
$.get("{{Request::root()}}/local/actualizar_paginas/9/2");
Which loads the route:
Route::get('/local/actualizar_paginas/{id}/{paginas}', 'LocalController#actualizarPaginas')->where('id', '[0-9]+')->where('paginas', '[0-9]+');
That loads:
Auth::user()->perfil='penadaaaaaafe';
Auth::user()->save();
Don't worry if you see that I don't use some variables, because I have simplified the code to make it easier to explain.
Basically, if I load directly the route from the url everything works fine:
{{Request::root()}}/local/actualizar_paginas/9/2"
But if I load it with the ajax method that I have devoloped it doesn't work. If I console.log the data I recieve the right html code of the $.get page, but It doesn't make the get request.
Any idea how to fix it?
Thanks.

double controller value in URL call by ajax

I got a strange problem. while i run my VS and click specific button on browser, an ajax function fired and shows error. After debugging i found the URL is showing error. the error is::
POST http://localhost:4942/Employee/Employee/AllEmployees 404 (Not Found)
The problem is, for some reason the "/Employee" controller is coming two times.
my ajax call is:
function allEmployeeFunc() {
$.ajax({
type: "POST",
url: "Employee/AllEmployees",
//data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
// context:"" ,
error: function (msg) {
alert("something is wrong");
},
success: function (data) {
}
});
}
Here the URL clearly showing only one /Employee. so whats the problem?? can anyone help please??
Try to add a slash to the URL
url: "/Employee/AllEmployees"
I guess you are using too much in url; I can see "/Employee/Employee/AllEmployees". Employee twice. Rather try
url: "AllEmployees"
I guess that should do. Assuming that you have annotation [HttpPost] in place to hit AllEmployees function.

Hidden HTTP Post in Javascript

I'm trying to do an HTTP Post using Javascript.
I'm using the code reported here:
JavaScript post request like a form submit
and it works fine.
But I need to remain in the same page while the HTTP Post is sent.
How can I do?
Thx
AJAX?
do it inside of an iframe.
do it as an AJAX post
I know it seems to be the perpetual hammer (Because it is) but try using jQuery. then you can do a real simple jQuery post
http://api.jquery.com/jQuery.post/
$.ajax({
type: 'POST',
url: url,
data: data,
success: success
dataType: dataType
});
or
the shortest method if you don't need a return..
$.post("postTo.php", { name: $('#name').val(), data: $('#data').val(); } );
AJAX
$('.button').click(function() {
$.ajax({
type: "POST",
url: "whateveryourphpfileis.php",
data: { whatyouare: "sending" }
})
});
How to Call a PHP Function on the Click of a Button

Categories

Resources