dtjzpg5313 2015-10-01 08:50
浏览 111

如何使用ajax将javascript变量传递给php

I want to pass javascript variable to php file. Here I attached my code

function Calculate(val)
    {

        var h = document.getElementById('xyz').textContent ;
        var result = h * val;
        result = result.toFixed(2);
        document.getElementById('lblRes').innerHTML ='$'+ result;
        $('#ori_price').hide();

        $.ajax ({
            url: 'nonmembersdetail1.php',
            type : 'POST',
            data : {val : h},
            success: function( result ) {
                alert( result );
            }
        });
   }

<?php
echo "<td ><label id='xyz' name='xyz'>".  $row->nonmember_price  ."</label></td>";
echo "<td ><input type='text' style='width:40px' id='words' name='qty' value='1' onchange='Calculate(this.value);'  /></td>";
?>

In my nonmembersdetail1.php code

echo ( $_POST['val'] );

I didn't get value in php file. Please anyone help me.Thanks in advance...

  • 写回答

2条回答 默认 最新

  • dongzhong5967 2015-10-01 08:59
    关注

    Check in you browser console, if the AJAX call is actually getting fired or you are getting any error before that. Because there is no error in the AJAX call and you should get the val value in POST array of PHP.

    评论

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM