Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.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
在php变量中设置ajax响应_Php_Ajax - Fatal编程技术网

在php变量中设置ajax响应

在php变量中设置ajax响应,php,ajax,Php,Ajax,我试图在php变量中设置json响应。响应成功后,我的html数据将打印在div中。 你知道如何把它上传到Php变量中吗。我不知道我可以把它存储在会话或cookies中的什么地方 $('#pincode').on('change', function() { //const formData = $('#formid').serializeArray(); var address = $("input[name=address]").val(); var pincode=

我试图在php变量中设置json响应。响应成功后,我的html数据将打印在div中。 你知道如何把它上传到Php变量中吗。我不知道我可以把它存储在会话或cookies中的什么地方

$('#pincode').on('change', function() {
    //const formData = $('#formid').serializeArray();
    var address = $("input[name=address]").val();
    var pincode= $("input[name=pincode]").val();
    var price = $("input[name=price]").val();
    var city = $("input[name=city]").val();
    var country =$('#country').val();
    var state = $('#state').val();
    //var state =$(this).val();
    //console.log(formData);

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $.ajax({
        type:'POST',
        data:{address:address, pincode:pincode, price:price,country:country,state:state,city:city},
        url:'./ava',
        dataType: "text",
        success:function(data){
            $('#gettax').html(data);
            //alert(res);
        },
        error: function (err) {
            console.log(err);
            alert("Something Went Wrong, Please check again");
        }
    });
});
这是我的控制器,我返回一个计划文本值,并尝试在php变量中恢复该值

public function avatax(Request $request){
    $input = $request->all();
    $address=$input['address'];
    $pincode=$input['pincode'];
    $country=$input['country'];
    $state=$input['state'];
    $city=$input['city'];
    $price=$input['price'];
    // print_r(json_decode(json_encode($input)));
    // die();
    //return response()->json(['success'=>$input]);

    $client = new Avalara\AvaTaxClient('phpTestApp', '1.0', 'localhost', 'sandbox');
    $client->withSecurity('ABC', 'ABC');
    // If I am debugging, I can call 'Ping' to see if I am connected to the server
    $p = $client->ping();
    echo('<h2>Ping</h2>');
    echo('<pre>' . json_encode($p, JSON_PRETTY_PRINT) . '</pre>');
    if ($p->authenticated == true) {
        echo '<p>Authenticated!</p>';
    }

    // Create a simple transaction for $100 using the fluent transaction builder
    $tb = new Avalara\TransactionBuilder($client, "ABC", Avalara\DocumentType::C_SALESINVOICE, 'ABC');
    $t = $tb->withAddress('SingleLocation',$address,null,null, $city,$state,$pincode, $country)
        ->withLine($price, 1, null, "P0000000")
        ->create();

    // echo('<h2>Transaction #1</h2>');
    // echo('<pre>' . json_encode($t, JSON_PRETTY_PRINT) . '</pre>');
    // echo '<pre>';print_r($t);

    $ta=$t->totalTax;

    // die();
    return response($ta)
        ->header('Content-Type', 'text/plain');
avatax公共功能(请求$Request){
$input=$request->all();
$address=$input['address'];
$pincode=$input['pincode'];
$country=$input['country'];
$state=$input['state'];
$city=$input['city'];
$price=$input['price'];
//打印(json解码(json编码($input));
//模具();
//return response()->json(['success'=>$input]);
$client=new Avalara\AvaTaxClient('phpTestApp','1.0','localhost','sandbox');
$client->with security('ABC','ABC');
//如果我正在调试,我可以调用“Ping”查看我是否已连接到服务器
$p=$client->ping();
回声(‘Ping’);
echo(“”.json_encode($p,json_PRETTY_PRINT)。“”);
如果($p->authenticated==true){
回显“已验证!

”; } //使用fluent transaction builder创建100美元的简单交易 $tb=new Avalara\TransactionBuilder($client,“ABC”,Avalara\DocumentType::C_SALESINVOICE,“ABC”); $t=$tb->withAddress('SingleLocation',$address,null,null,$city,$state,$pincode,$country) ->withLine($price,1,null,“p000000”) ->创建(); //echo(‘交易#1’); //echo(“”.json_encode($t,json_PRETTY_PRINT)。“”); //回音“;打印费($t); $ta=$t->totalTax; //模具(); 回复(ta) ->标题(“内容类型”、“文本/普通”);
您的问题非常不清楚。您想存储什么,何时何地?请给我们一些示例,说明您希望发生什么,以及当前发生了什么。如果我理解得很好,您希望在php变量中设置ajax请求的json响应。据我所知,这是不可能的,或者如果您在.php文件中编写js,但完全是我们的问题因为请求完成了,你得到了响应,你的js脚本也会用它做一些事情,但这发生在你的浏览器中,所以php不再相关了。。。