I have this code, to simple update "cupom" from "0" to "1", but it isnt working with Chrome, with firefox it does work, any help/advice is welcome.
var req;
function val_impressao_js(cpf) {
if(window.XMLHttpRequest) {
req = new XMLHttpRequest();
}
else if(window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
var url = "val_impressao.php?cpf="+cpf;
req.open("GET", url, true);
req.onreadystatechange = function()
{
if(req.readyState == 4 && req.status == 200)
{
window.print();
}
}
req.send(null);
}
val_impressao.php
require "arqinc/conexao.php";
require "arqinc/funcoesbd.php";
$cpf=$_GET['cpf'];
$query=mysql_query("UPDATE cadcoo SET cupom=1 WHERE cpf_cadpessoafisica=$cpf AND cupom=0");
And by the way, this part isnt working too, it does not print the page.
if(req.readyState == 4 && req.status == 200)
{
window.print();
}
I suggest the following script, as it can even work with IE7 and all the modern browsers.
window.onload = initAll;
var xhr = false;
function initAll() {
document.getElementById("requestXML").onclick = makeRequest;
}
function makeRequest() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { }
}
}
if (xhr) {
xhr.onreadystatechange = showContents;
xhr.open("GET", "us-states.xml", true);
xhr.send(null);
}
else {
document.getElementById("updateArea").innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
}
return false;
}
function showContents() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var outMsg = xhr.responseText;
}
else {
var outMsg = "There was a problem with the request " + xhr.status;
}
document.getElementById("updateArea").innerHTML = outMsg;
}
}