doulian7305 2015-06-27 23:15
浏览 94
已采纳

将数据提交给PHP,并获得结果

I would like to submit some data. Weather this be using a form, or onClick execute some AJAX, I'm not sure.

For example, I have this input

<input id='inpamount' type="text" name="amount" value="2.00" onkeyup="pad();validatemin();product()">

Now say if I wanted to send this data to a PHP file, using post ( i could just add a form). But then, without reloading the page (I can do this), how could I fetch a response (using AJAX).

Essentially I would like a user to be able to press a button, then to submit the inputs to a php file, and then get the output and assign it to a variable (I know how to do this, I just want to be able to get the data.

The php execute takes a few centiseconds because it comunicates with SQL. (If this matters).

I have considered using invisible forms but it didn't seem to work

If anyone could point me in the right direction, that would be great.

  • 写回答

1条回答 默认 最新

  • dqwh1208 2015-06-27 23:22
    关注

    Something like this?

    $(document).ready(function(e) {
    
           $('#inpamount').click(function() {
    
                var data = 'myValue=' + $(this).val();
    
                $.ajax({
                    url: "yourscript.php",
                    type: "POST",
                    data: data,
                    cache: false,
                    success: function(scriptOutput) {
                       //handle the result
                        }
                    }
                });
                return false;
            });
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?