Javascript 在js变量中插入html div值

Javascript 在js变量中插入html div值,javascript,payment-gateway,send,Javascript,Payment Gateway,Send,我在页面底部有以下代码来更新金额(p_amount)和包裹id(pack_id)(所有代码都在同一页面中) jQuery.ajax({ url:ajaxurl, 数据类型:“json”, 类型:“post”, 数据:搜索参数, 成功:功能(响应){ 如果(response.code=='success'){ jQuery(“#优惠券结果”).html('admin/files/images/right_icon.png“>”); }否则{ jQuery(“#优惠券结果”).html('admin

我在页面底部有以下代码来更新金额(p_amount)和包裹id(pack_id)(所有代码都在同一页面中)

jQuery.ajax({
url:ajaxurl,
数据类型:“json”,
类型:“post”,
数据:搜索参数,
成功:功能(响应){
如果(response.code=='success'){
jQuery(“#优惠券结果”).html('admin/files/images/right_icon.png“>”);
}否则{
jQuery(“#优惠券结果”).html('admin/files/images/error_16x16.png“>”);
}
jQuery('#p#amount').html(response.p#amount);
}
在此之后,它将更新此处的值

    <div class="col-md-8 col-xs-8 col-sm-8 " id="p_amount">     

在页面的中间,我使用JS在我的支付网关提供商上发送值,我想在里面插入更新的金额值(PyPoT)。 (var金额),但它从不更新

 <div class="checkout">    
  <script type="text/javascript">
    var amount       = 'p_amount';
    var currency     = 'USD';   

var金额=‘p_金额’;
风险值货币=‘美元’;

更新js变量响应函数

jQuery.ajax({                    
        url : ajaxurl,                   
        dataType : "json",
        type : "post",
        data : search_params,
        success : function(response){
            if(response.code=='success'){                           
                jQuery('#coupon-result').html('<img src="<?php echo WP_iv_membership_URLPATH; ?>admin/files/images/right_icon.png">');
                amount = response.p_amount;
            }else{
                    jQuery('#coupon-result').html('<img src="<?php echo   WP_iv_membership_URLPATH; ?>admin/files/images/wrong_16x16.png">');
            }
            jQuery('#p_amount').html(response.p_amount);

                }
jQuery.ajax({
url:ajaxurl,
数据类型:“json”,
类型:“post”,
数据:搜索参数,
成功:功能(响应){
如果(response.code=='success'){
jQuery(“#优惠券结果”).html('admin/files/images/right_icon.png“>”);
金额=响应的p_金额;
}否则{
jQuery(“#优惠券结果”).html('admin/files/images/error_16x16.png“>”);
}
jQuery('#p#amount').html(response.p#amount);
}

使用全局变量并更新值。如果我使用window.location.href并在url中发送值,我可以将其存储在php中并打印出来,但问题是我不希望页面刷新。因此,使用这种方式,我很抱歉,我没有让您知道所有这些值都已更新和更正。输出仍然是这样->var amount='package\u amount';where应该用一些数字来更新抱歉这个->var amount='p_amount';哦,我知道你需要从页面中间删除这个变量
amount
currency
,并在Ajax的响应函数中初始化。与上面的答案类似。这段代码是jQuery('p_amount').html(response.p_amount);更新包含id=p_amount的div,但是当我在这里使用它时,var amount='p_amount';这个var amount什么也得不到。
jQuery.ajax({                    
        url : ajaxurl,                   
        dataType : "json",
        type : "post",
        data : search_params,
        success : function(response){
            if(response.code=='success'){                           
                jQuery('#coupon-result').html('<img src="<?php echo WP_iv_membership_URLPATH; ?>admin/files/images/right_icon.png">');
                amount = response.p_amount;
            }else{
                    jQuery('#coupon-result').html('<img src="<?php echo   WP_iv_membership_URLPATH; ?>admin/files/images/wrong_16x16.png">');
            }
            jQuery('#p_amount').html(response.p_amount);

                }