1

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();

    }
4

1 回答 1

0

我建议使用以下脚本,因为它甚至可以与 IE7 和所有现代浏览器一起使用。

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;
    }
}
于 2013-02-18T17:02:42.230 回答