[英]$.post(“file.php”,{},null, “json”).done(function(data){} doesen't work (Does not load the dada from php)
I amb trying to let work a $.post jquery function using JSON data, but the case is that when I expect to return the data, looks like the method is never called, or never triggered. 我试图使用JSON数据来使$ .post jquery函数起作用,但是这种情况是,当我希望返回数据时,似乎从未调用或从未触发过该方法。 I don't understand why in this case is not working, when I just made a copy/paste from the same code in the same .php file. 当我只是从同一.php文件中的同一代码进行复制/粘贴时,我不明白为什么在这种情况下不起作用。 Here I let you the code: 这里我让你的代码:
$.post("operacions/obtenirIdUs.php", {idUsConcret : idUsConcret}, null, "json").done(function(data){
alert("hello there");
$("#NomUsuariLinea").val(data.Nom);
$("#LlinatgesUsuariLinea").val(data.Llinatges);
$("#ContrassenyaUsuariLinea").val(data.contrassenya);
$("#EmailUsuariLinea").val(data.email);
})
The alert is never shown. 该警报从不显示。 I would really apreciate any solution, due the case that this code is working with other examples in the same page as I said before. 我真的很喜欢任何解决方案,因为这种情况下代码可以与我之前说过的页面中的其他示例一起使用。
Here I let you my php.file: "obtenirIdUs.php" 在这里,我让您使用我的php.file:“ obtenirIdUs.php”
<?php
include("../connexio.php");
$idUsConcret= $_POST['idUsConcret'];
$arrayDatos = array();
$EditarFactura = "SELECT * FROM usuari WHERE idUsuari = '".$idUsConcret."'";
echo $EditarFactura;
$connexio = mysqli_query($conn,$EditarFactura) or die(mysqli_error());
while($llistaFactura = mysqli_fetch_array($connexio)){
$arrayDatos['Nom'] = $llistaFactura['Nom'];
$arrayDatos['Llinatges'] = $llistaFactura['Llinatges'];
$arrayDatos['contrassenya'] = $llistaFactura['contrassenya'];
$arrayDatos['email'] = $llistaFactura['email'];
$arrayDatos['rol'] = $llistaFactura['rol'];
}
echo json_encode($arrayDatos);
?>
Once again, thank you. 再次感谢您。
尝试将“完成”替换为“成功”:
$.post("operacions/obtenirIdUs.php", {idUsConcret : idUsConcret}, null, "json").success(function(data){...});
try this: 尝试这个:
$.post("operacions/obtenirIdUs.php", {idUsConcret : idUsConcret}, null, "json").then(
function(data){
//handle your data
},function(err){
//handle error
});
I've already solved the mistake, I had a echo "hello"; 我已经解决了这个错误,回声为“ hello”。 on the php file, and cause of that the json encode was not working. 在php文件上,导致json编码不起作用的原因。
Thank you all of you who tried to help me. 谢谢所有试图帮助我的人。
Have a good day! 祝你有美好的一天!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.