1

「cupom」を「0」から「1」に単純に更新するためのこのコードがありますが、Chromeでは機能しません。Firefoxでは機能します。ヘルプ/アドバイスは大歓迎です。

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

ちなみに、この部分も機能していません。ページを印刷しません。

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 に答える