将jQuery值传递给PHP

将jQuery值传递给PHP

本文介绍了将jQuery值传递给PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery计算两个位置之间的距离,我想将此值(pickup_distance)传递给PHP.

I am calculating the distance between two places using jQuery and I want to pass this value (pickup_distance) for use in PHP.

我想将此值发送到riff.fare.controller.php,以用于以下功能:

I am wanting to send this value to tariff.fare.controller.php for use in the following function:

private static function getFare($int_terminate) {

    // Function

    if pickup_distance(<-- jQuery Value) > 5 {

        // Do Something

    }

}

我该怎么做呢?我知道我可以通过AJAX来做到这一点,但是对于编程新手来说,我不确定如何做到这一点.

How could I go about doing this? I'm aware I can do this via AJAX but being quite new to programming I'm not quite sure how I can do this.

任何帮助将不胜感激!

推荐答案

使用Jquery很简单:

using Jquery it's quite easy:

var your_var_value=1200;
$.post("your_php_script.php", {var_value: your_var_value}, function(data){
    alert("data sent and received: "+data);
});

然后在您的PHP脚本中,您将获得如下所示的变量:

then in your PHP script you get the variable like this:

$distance=$_POST['var_value'];

您在"your_php_script.php"中回显的内容将作为data变量返回.

And what you echo in "your_php_script.php" is returned as the data variable.

这篇关于将jQuery值传递给PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 02:35