Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery在发布后发布_Javascript_Php_Jquery_Ajax_Stripe Payments - Fatal编程技术网

Javascript JQuery在发布后发布

Javascript JQuery在发布后发布,javascript,php,jquery,ajax,stripe-payments,Javascript,Php,Jquery,Ajax,Stripe Payments,我有一个页面使用条纹来购买物品。下面的javascript代码是通过AJAX和PHP填充项目,并将其作为输入字段插入的代码。然后,它侦听正在提交的表单。它检查信用卡凭证是否完好。如果是这样的话,它应该发布到另一个PHP文件,该文件将检查所有其他凭据。它将返回错误或成功。不幸的是,这个post函数不执行,而是执行它工作之前的所有操作 我甚至尝试将其发布到基本php文件中,该文件回显一个字符串,以便查看它是否是php错误。仍然没有显示任何内容。我删除了POST变量并将其更改为get方法。现在,它工作

我有一个页面使用条纹来购买物品。下面的javascript代码是通过AJAX和PHP填充项目,并将其作为输入字段插入的代码。然后,它侦听正在提交的表单。它检查信用卡凭证是否完好。如果是这样的话,它应该发布到另一个PHP文件,该文件将检查所有其他凭据。它将返回错误或成功。不幸的是,这个post函数不执行,而是执行它工作之前的所有操作

我甚至尝试将其发布到基本php文件中,该文件回显一个字符串,以便查看它是否是php错误。仍然没有显示任何内容。我删除了POST变量并将其更改为get方法。现在,它工作了,并在div#post输出中显示了字符串。因此,有一些东西阻止将其发布到PHP文件中:/

$(document).ready(function(){
    // CHECK IF LOGGED IN
    $.get( "http://mywebsite.com/logincheck.php", function( data ) {
        if (data === "false") {
            window.location = "register.html";
        }
    });

    // PROCESS AND GET ALL OF THE CONTENT FROM THE DATABASE
    var qpon_id   = localStorage.qponid;
    var shop_id   = localStorage.shop;
    var qg        = localStorage.qg;
    var variation = localStorage.variation;
    var deuce     = localStorage.deuce;
    var thrice    = localStorage.thrice;

    $.post("http://mywebsite.com/cart.php", {qg : qg, variation : variation, id : qpon_id, deuce : deuce, thrice : thrice, shop : shop_id}, function(data) {
        if (data.length > 0) {
            $( "#qponcart" ).html( data );
        }
    });


    // Watch for a form submission:
    $("#purchase-qpons").submit(function(event) {

        var error = false;

        // disable the submit button to prevent repeated clicks:
        $('#submit').attr('disabled', 'disabled');


        // Get the values:
        var ccNum    = $('.card-number').val();
        var cvcNum   = $('.card-cvc').val();
        var expMonth = $('.card-expiry-month').val();
        var expYear  = $('.card-expiry-year').val();

        // Validate the number:
        if (!Stripe.validateCardNumber(ccNum)) {
            error = true;
            reportError('The credit card number appears to be invalid.');
        }

        // Validate the CVC:
        if (!Stripe.validateCVC(cvcNum)) {
            error = true;
            reportError('The CVC number appears to be invalid.');
        }

        // Validate the expiration:
        if (!Stripe.validateExpiry(expMonth, expYear)) {
            error = true;
            reportError('The expiration date appears to be invalid.');
        }

        if (!error) {
            // Clear any current errors
            $('#payment-errors').html('');

            // Get the Stripe token:
            Stripe.createToken({
                number: ccNum,
                cvc: cvcNum,
                exp_month: expMonth,
                exp_year: expYear
            }, stripeResponseHandler);
        }

        // Prevent the form from submitting:
        return false;

    }); // form submission

});


function reportError(msg) {
    // Show the error in the form:
    $('#payment-errors').text(msg).addClass('meow alert-error fade in');

    // Re-enable the submit button:
    $('#submit').removeAttr('disabled');

    return false;
}



// Function handles the Stripe response:
function stripeResponseHandler(status, response) {

    // Check for an error:
    if (response.error) {
        reportError(response.error.message);

    } else { // No errors, submit the form:

        var formcontainer = $("#purchase-qpons");

        // Token contains id, last4, and card type:
        var token = response['id'];

        // Insert the token into the form so it gets submitted to the server
        formcontainer.append("<input type='hidden' name='stripeToken' id='stripeToken' value='" + token + "' />");

        // POST TO THE SERVER
        $.post("http://mywebsite.com/purchase.php", {stripeToken : $("#stripeToken").val(), charge_total : $("#charge_total").val()}, function(data){
            if (data.length > 0) {
                $( "#post-output" ).html( data );
            } 
        });

    }

} // End of stripeResponseHandler() function.
$(文档).ready(函数(){
//检查是否已登录
$.get(”http://mywebsite.com/logincheck.php,函数(数据){
如果(数据==“假”){
window.location=“register.html”;
}
});
//处理并从数据库中获取所有内容
var qpon_id=localStorage.qponid;
var shop_id=localStorage.shop;
var qg=localStorage.qg;
var variation=localStorage.variation;
var deuce=localStorage.deuce;
var thrice=localStorage.thrice;
$.post(”http://mywebsite.com/cart.php“,{qg:qg,variation:variation,id:qpon_id,deuce:deuce,thrice:thrice,shop:shop_id},函数(数据){
如果(data.length>0){
$(“#qponcart”).html(数据);
}
});
//注意表单提交:
$(“#购买qpons”)。提交(功能(事件){
var错误=错误;
//禁用“提交”按钮以防止重复单击:
$('提交').attr('禁用','禁用');
//获取值:
var ccNum=$('.card number').val();
var cvcNum=$('.card cvc').val();
var expMonth=$('.card expiration month').val();
var expYear=$('.card expirement year').val();
//验证号码:
如果(!Stripe.validateCardNumber(ccNum)){
错误=真;
reportError('信用卡号似乎无效');
}
//验证CVC:
如果(!Stripe.validateCVC(cvcNum)){
错误=真;
reportError('CVC编号似乎无效');
}
//验证过期时间:
如果(!Stripe.validateExpiry(expMonth,expYear)){
错误=真;
reportError('到期日期似乎无效');
}
如果(!错误){
//清除所有当前错误
$(“#支付错误”).html(“”);
//获取条带标记:
Stripe.createToken({
编号:ccNum,
cvc:cvcNum,
exp_月:exp月,
出口年份:出口年份
},stripeResponseHandler);
}
//阻止表单提交:
返回false;
});//表格提交
});
函数报告错误(msg){
//在表单中显示错误:
$(“#支付错误”).text(msg.addClass('meow alert error fade-in');
//重新启用“提交”按钮:
$(“#提交”).removeAttr('disabled');
返回false;
}
//函数处理条带响应:
函数stripeResponseHandler(状态、响应){
//检查是否有错误:
if(response.error){
reportError(response.error.message);
}否则{//没有错误,请提交以下表格:
var formcontainer=$(“#购买qpons”);
//令牌包含id、last4和卡类型:
变量标记=响应['id'];
//将令牌插入表单,以便将其提交到服务器
formcontainer.追加(“”);
//发送到服务器
$.post(”http://mywebsite.com/purchase.php“,{stripeToken:$(“#stripeToken”).val(),费用总额:$(“#费用总额”).val()},函数(数据){
如果(data.length>0){
$(“#后期输出”).html(数据);
} 
});
}
}//stripeResponseHandler()函数的结尾。

查看浏览器控制台的“网络”选项卡,查看是否发出请求,如果是,状态、发送的数据、返回的数据等是什么?呵呵,聪明的思维。变量不可用不确定这到底意味着什么…假设你发现了这样的问题。。。var qpon_id=localStorage.qponid;