如何使用Ajax数据发送到PHP文件 [英] How to send data to php file using ajax

查看:86
本文介绍了如何使用Ajax数据发送到PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找四处打听如何做到这一点,但我找不到任何基本足够满足我的需求。

I have been searching around to find out how to do this but I can't find anything basic enough for my needs.

我想创建一个5星级评级系统,如果3星被点击,例如它通过'3','$变量1'和'$变量2到rate.php

I want to create a 5 star rating system, that if the 3rd star is clicked for example it passes '3', '$variable1' and '$variable2' to 'rate.php'

然后我就可以创建rate.php一个脚本,将查询到正确的表等。

I can then create a script in rate.php to insert a query into the correct table etc.

我能做到这一点正常,但不能使用Ajax。我怎样才能做到用ajax呢?

I can do this normally, but not using Ajax. How can I do it using ajax?

推荐答案

请不要期望比这更多的解释,而不显示您的code,您搜索的内容你已经尝试过什么。

Please don't expect much more explanation than this without showing your code, what you've tried and what you've searched.

这显示了如何做到这一点的一般格式。您将需要得到你的实际值到code。

This shows the general format of how to do it. You will need to get your actual values into the code.

$.post('otherfile.php', {
    stars  : 3, 
    value1 : '$variable1', //whatever this is
    value2 : '$variable2'  //whatever this is
}, function(){
    alert('done');
});

在PHP端...

On the PHP Side ...

echo $_POST['stars'];
echo $_POST['value1'];
echo $_POST['value2'];

这篇关于如何使用Ajax数据发送到PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆