[英]How to: PHP $_POST vars to AJAX $.ajax post call on a JS?
[英]How to call a php file with ajax post
//文件inserirPF.js
function add(){
var metodo = 'AdicionaPessoa';
$.ajax({
url: "../class/dao/InserirPFDao.class.php",
type: 'POST',
data: {Metodo:metodo, NOME_:NOME, EMAIL_:EMAIL, SENHA_:SENHA},
success: function(data) {
alert(data);
}
});
}
//文件InserirPFDao.class.php
<?php
require_once("../class/dao/connection.class.php");
class InserirPFDao extends ConexaoMySQl
{
function __construct(){
parent::Connection();
if (isset($_POST['Metodo'])) {
switch ($_POST('Metodo')) {
case 'AdicionaPessoa':
$retorno = AdicionaPessoa();
mysql_close($db);
echo $retorno;
break;
default:
echo "Nenhum metodo encontrado!"
break;
}
}
}
public function AdicionaPessoa(){
try {
$NOME_ = $_POST("NOME_");
$EMAIL_=$_POST("EMAIL_");
$SENHA_=$_POST("SENHA_");
$Adiciona = mysql_query("INSERT INTO PESSOA (NOME, EMAIL, SENHA)VALUES('".$NOME_."','".$EMAIL_."','".$SENHA_."')");
if($Adiciona)
return true;
else
return false;
}
catch (Exception $e) {
}
}
}
?>
如何調用jQuery arquivoEstou,以嘗試使用ajax在Javascript和php之間建立連接。 如果有人知道另一種方法...向我顯示此錯誤:
<font size='1'>
<table class='xdebug-error xe-parse-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr>
<th align='left' bgcolor='#f57900' colspan="5">
<span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span>
Parse error: syntax error, unexpected T_PUBLIC in C:\Arquivos de programas\VertrigoServ\www\gofinder\class\dao\InserirPFDao.class.php on line
<i>7</i>
</th>
</tr>
</table>
$retorno = AdicionaPessoa();
看起來不正確。 我猜你的意思是:
$retorno = $this->AdicionaPessoa();
就像注釋中指出的那樣,您正在創建一個類,但不對其進行任何操作。 您需要實例化該類。 將以下內容添加到文件末尾:
$inserirPFDao = new InserirPFDao();
您可能需要閱讀一些基本的面向對象編程教程,以幫助您入門。 您看起來好像在混合OO和過程代碼,卻不了解它們之間的差異。
閱讀以下內容: http : //net.tutsplus.com/tutorials/php/object-oriented-php-for-beginners/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.