Ajax,PHP

编程入门 行业动态 更新时间:2024-10-23 04:51:46
本文介绍了Ajax,PHP-从数据库获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在收集从数据库中获取的数据时遇到一些问题.不知道如何继续.

i have some problems with collecting the data i fetch from database. Dont know how to continue.

到目前为止我做了什么:

What i did so far:

JQ:

$(document).ready(function(){ $('#submit').click(function(){ var white = $('#white').val(); $.ajax({ type:"POST", url:"page.php", data:{white:white} }); }); });

到目前为止,

PHP(需要的page.php):

$thing = mysql_real_escape_string($_POST["white"]); ..database connect stuff.. $query = "SELECT * FROM table1 WHERE parameter='$thing'"; if($row = mysql_query($query)) { while (mysql_fetch_array($row)) { $data[]=$row['data']; } }

我不知道的是如何使用ajax发送和接收数据.

What i dont know, is how to send out data and receive it with ajax.

请求不成功怎么办?

ajax调用对数据库注入的安全性如何?

How secure is ajax call against database injection?

谢谢:)

推荐答案

拨打电话后,您需要在$.ajax()中使用success参数来获得响应

You'll need a success parameter in $.ajax() to get a response once a call is made

$('#submit').click(function(){ var white = $('#white').val(); if(white == '') { // display validation message } else { $.ajax({ type:"POST", url:"page.php", data:{"white":white} success:function(data){ $('#someID').html(data); } }); });

在page.php中回显的任何内容(HTML标记或变量)将显示在ID为someID的元素中,最好将其保留为<div>

Whatever you echo (HTML tags or variables) in page.php will be shown in the element whose ID is someID, preferable to keep the element a <div>

在page.php中,您可以使用$_POST['white']捕获输入元素中输入的值,并将其用于执行您想执行的任何DB操作

In page.php, you can capture the value entered in the input element by using $_POST['white'] and use it to do whatever DB actions you want to

更多推荐

Ajax,PHP

本文发布于:2023-10-27 15:42:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533815.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Ajax   PHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!