Here I request print after I insert into a mysql db that the page was printed(I did not find a way to trigger the insert after the page is printed so I put it before), which is inside a $(document).ajaxComplete() block:
$("#bPrintIes").off().on("click",function(){
if(confirm("Confirmati Printarea!")){
var codCom=$("#codCom").val();
$.ajax({
type:"POST",
url:"php/facturi/iesirePrintare.php",
data:{ies:"print",codCom:codCom}
}).done(function(){
window.print();
});
}
});
#bPrintIes is a button, in case you needed to know.
First issue is that it shows a second dialog which asks the user to
"block future messages".
Second issue is that prints another blank page.
The issues are inside Firefox and IE, Chrome does it's job.
I want to show the print dialog and when I press Ok/Accept it should print the page, without the dialog to "block future messages" from the page and without the blank page.
I am ussing JQuery 1.10.2.
Any ideeas/suggestions?
Thank you.
Related
i need to call a click event from another file...
On my index.php I have a 'select' to choose a name, once I did, I call by Ajax a form by the name I choosed before, this form is on espacio.php, once I complete the form I must have to click a button to save the info, when I click this button the info are passed by Ajax to espacio2.php and there is here where I show a success or a failure message.
This message shows on my index.php and this is good, but I want to hide it after a few seconds.
How can I call the click event from espacio.php?
This is a code that works only if a click is pressed on the same page:
$(document).ready(function(){
$(".botoncete").click(function(){
$(".prueba").fadeIn();
Esconder();
});
function Esconder(){
setTimeout(function() {
$(".prueba").fadeOut();
},2000);
}
});
I've already solved the problem, thanks to #Barmar, and as he said: "If you're sending the data by AJAX, you stay on the same page".
I really don't know what was I thinking...
I work on a php file that contains a simple register form. I send the data to my mysql database via jQuery.click event. When the data goes to database, a massage display below the button, after 3 seconds it disappear and the input areas clean by jQuery. If I don't refresh the page and keep going to send data to my database, when I click the button, data go to database, input fields clean but message doesnt appear second time. I hope you could help me. Here is the jQuery code that I use;
$(document).ready(function(){
$('#submit').click(function(){
$.post("add_user2.php", $("#addUser").serialize(), function(response) {
$('#success').html(response);
$('#success').hide(3000);
$("#users_name").val('');
$("#users_mail").val('');
$("#users_phone").val('');
$("#users_schoolnumber").val('');
$("#users_faculty").val('');
$("#datepicker").val('');
});
return false;
});
});
This is the problem:
$('#success').hide(3000);
You are hiding your message box so when you execute it again, the message of the box will be the response variable but you will not see it as it is hidden.
You should show your message box when you want to display the message.
For example like:
$('#success').html(response).show();
$('#success').hide(3000);
I am making a test project in PHP. I want to show some information on click of button named 'View Details'. But there are 3 different buttons like this. Each are showing different information. I want to manage like user can see only one information at a time. Can Any one help me?
Thanks in advance.
You will manage flag to show/hide your information.
e.g if any one click on view details button you have set flag=1 in javascript and check this flag on another button click if is already 1 then does not display any information.
You could create a wrapper div say "resultsDiv" and display the response (ajax) from your php file to this DIV. So that only one information is seen at a time, like:
//First ajax call on first button click,
$.ajax({
...
..
success: function(resp) {
$("#resultsDiv").html(''); //clear the DIV html
$("#resultsDiv").html(resp); //place the response
}
});
//Second ajax call on second button click,
$.ajax({
...
..
success: function(resp) {
$("#resultsDiv").html('');
$("#resultsDiv").html(resp);
}
});
//more ajax calls
//your div that will hold response of ajax call on various button clicks
<div id="resultsDiv"></div>
Did you mean something like this
I use AJAX POST to send form data to an external script and attempting to hide the form on submit and prompt the user to download the script.
The script itself works well (uses fpdf to output pdf file for download). For some reason, prompting the user to download though never comes through.
My Ajax request is currently:
$.ajax({
url: "file.php",
type: "POST",
data: data,
cache: false,
success: function (html) {
//hide the form
$('#form').fadeOut('slow');
//display results
$('#form_results').fadeIn('slow');
$("#form_results").html(html);
}
});
file.php (on it own) will generate and display a PDF using FPDF. By setting the Output to I, the document is output to a browser, setting to 'D', it would normally force a download if I were simply accessing file.php directly.
any ideas?
Unfortunately you can't force a download directly from an ajax call. Your best bet is to submit the form through ajax and have ajax respond with a url that you can redirect the user to that starts the download. However, just an FYI, using location.href to a page that sends a header to force download in IE will cause the yellow security bar to appear on the top of the page. This happens in IE8, not sure about other versions. FF and Chrome don't have a problem with it.
Edit:
Just wanted to add, when you do redirect someone to a page that forces download, they don't actually leave the page they currently are on. So they won't have to reload an ajax page or anything. The download dialog will just show up. So if you are on index.php and you say location.href='download.php' and download.php forces a download. You just get the download dialog and don't leave index.php.
Edit2:
there are actually quite a few questions about this already.
https://stackoverflow.com/search?q=force+download+over+ajax
The problem is you try to show results but it is in form, which is hidden. Try something like :
//hide the form
$('#form').children().fadeOut('slow');
//display results
$('#form results').fadeIn('slow');
$("#form results").html(html);
This way, every children will be hidden but the parent itself won't.
I am working with a dynamically generated page written in PHP. The divon the page contain contents listed FancyBox links that open editing screens.
Once editing is complete and the user closes the FancyBox modal the changes
need to be reflected on the parent page.
Right, so I was able to find a solution that refreshes the entire page on submit
using
parent.location.reload (true);
to refresh the entire parent page. But, that causes a browser prompt
that is confusing to users and a bit of over kill as I really only
need the information edited to refresh.
how can I get just a single div to refresh on submit as
apposed to the entire page??????
You need to submit the form through AJAX. Since your using something that uses jQuery, you can use it to do it.
Here you can find a tutorial on how to do it
I think the best way is loading page fragments with .load().
something like,
$('#pageNeedToBeRefreshed').load('test.html #pageNeedToBeRefreshed');
User ,
It should be pretty easy
have a div place holder like below
<div id="dataToRefresh"> </div>
Once you close the dialog, have a event handler...
$('dataToRefresh').html('testing'); // give your data here
it should upate the parts of the page
let me know if you need anything else
please go thruogh .html api for more info
http://api.jquery.com/html/
Suppose you have the below div to refresh:
Then write
$("#dataToRefresh").load();
Might it will be helping you
Instead of using submit in html you can submit your form using the ajax -
$('#formid').submit(function(){
var data = $(this).serialize(); //this gives you the data of all elements of form in serialized format
$.ajax({
type: 'POST',
dataType:"json",
url: 'your url',
data: data,
success: function(data){
//replace the contents of the div you want to refresh here.
}
});
});
jQuery('#id_of_div').load('/url/to/updated/html');
See jQuery docs for load()