jquery ajax响应未发送

时间:2012-08-02 12:28:03

标签: php jquery

我有一个表单,使用post方法将其内容提交到php脚本,该脚本返回xml个文件。我发现问题在于检测到什么是错误的,我在firefox控制台中没有看到任何错误,这是jquery代码:

$(document).ready(function() {
$('form').submit( function() {
//alert('bonjour');
var pr= $('#prenom').val(); 
var te=$('#tech').val();
var sk=$('#skills').val() ; 
$("#form1").ajaxError(function(){
alert("An error occured!");
});
$.ajax({
url: "filter.php",
type: "POST",
data: { prenom: pr , tech: te , skills: sk },

dataType: "xml",
success: function(data) {
//alert(data);
$(data).find('collaborateur').each(function(){

var id = $(this).attr('id');
var urlPhoto = $(this).find('urlphoto').text();
var nb_cv = $(this).find('nb_cv').text();
var poste = $(this).find('poste').text();
var nb_ann_exp = $(this).find('nb_ann_exp').text();
var identite = $(this).find('identite').text();
var nom = $(this).find('nom').text();
var prenom = $(this).find('prenom').text();
$('<div class="items" id="link_'+id+'"></div>').html('<a href="'+urlPhoto+'"  

style="float:left">'+nom+'</a><span>'+nom+' '+prenom+'</span>').appendTo('#result');

}

);
//$('#result').html(data);
alert('Load was performed.');
},
fail: function(){alert ('fail');}
});
});
}); 

生成php xml的{​​{1}}代码低于

filter.php

过滤功能

 header('Content-type: text/xml');
 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 echo '<collaborateurs>';
 include("connection.php");
 require("functions.php");
 $tab = array();
 $tab = filter($_POST['prenom'], $_POST['tech'], $_POST['skills']);
 // print_r($tab);
 // exit;
 foreach  ($tab as $key => $value)
 {
 echo '<collaborateur id="'.$key.'">';
 echo '<nom>'.$value['nom'].'</nom>';
 echo '<prenom>'.$value['prenom'].'</prenom>';
 echo '<nb_cv>'.$value['nb_cv'].'</nb_cv>';
 echo '<poste>'.$value['poste'].'</poste>';
 echo '<nb_ann_exp>'.$value['nb_exp'].'</nb_ann_exp>';
 echo '<identite>'.$value['ident'].'</identite>';
 // echo '<nb_visite>'.$value['nb_visite'].'</nb_visite>';
 echo '</collaborateur>';
 } 
 echo '</collaborateurs>';

我在没有function filter($pren, $tech, $comp) {global $connection; $tab = array(); $query="SELECT DISTINCT c.id_c,`prenom`,`nom`,`nb_exp`,`ident`,`poste` , NomPhoto, nb_cv FROM `collaborateur` c, techno_mai m , competence_cle cc where( prenom like '$pren' or (m.lib_tech like '$tech' and m.id_c =c.id_c ) or (cc.id_c = c.id_c and cc.lib_cc like '$comp')) "; $c12=mysql_query($query, $connection)or die(mysql_error()); $i =0; while($fil= mysql_fetch_array($c12)) { $tab[$i]['prenom'] =$fil['prenom']; $tab[$i]['nom']= $fil['nom']; $tab[$i]['nb_exp']=$fil['nb_exp']; $tab[$i]['ident']=$fil['ident']; $tab[$i]['poste']=$fil['poste']; $tab[$i]['NomPhoto']=$fil['NomPhoto']; $tab[$i]['nb_cv']=$fil['nb_cv']; $tab[$i]['nom']=$fil['nom']; $tab[$i]['prenom']=$fil['prenom']; $i++; } return $tab; } 的表单中测试了php代码,并呈现了正确的ajax文件。 没有ajax的服务器输出(xml文件)

xml

提前谢谢。

1 个答案:

答案 0 :(得分:1)

您正在设置

data: { prenom: pr , te: tech , sk: skills },

然后重新开始

 $tab = filter($_POST['prenom'], $_POST['tech'], $_POST['skills']);

应该是

data: { prenom: pr , tech: te , skills: sk},