Jump to content
chicote

Erro em função jquery

Recommended Posts

chicote

Boa noite,

Estou praqui a tentar enviar um valor para um ficheiro php, e receber resposta desse mesmo ficheiro, isso automaticamente. Mas algo esta a correr mal. Eu sou iniciante nesta area e tou com alguma dificuldade. Alguem por favor me consegue ajudar?

Deixo em baixo o codigo jquery, esta alguma coisa nele mal que esta a bloquear o funcionamento total do site.

<script>

           $(document).ready(function() {

           var myLast = 'sendlast='+ $("#send_total").val();

           var auto_refresh = setInterval(

           jQuery.ajax({
           type: "POST",
           url: "auto_load_news.php",
           dataType:"text",
           data:myLast,

           success:function ()
           {
           $('#have_news').load('auto_load_news.php').show("slow");
           },
           error:function (xhr, ajaxOptions, thrownError){
           alert(thrownError);
           }
           }),
           2000);

           });
</script>

<?php
include("config.php");

if(isset($_POST["sendlast"]))
{

$last = filter_var($_POST["sendlast"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);


$result = $mysqli->prepare("SELECT idpost FROM post ORDER BY idpost DESC LIMIT 1");
$result->execute(); //Execute prepared Query
$result->bind_result($idposta); //bind variables to prepared statement



while($result->fetch()){
if($idposta > $last){

   echo "Existem novos posts";
}
else{

}
}
}
?>

Edited by chicote

Share this post


Link to post
Share on other sites
HappyHippyHippo

success: function(reply)
{
 //$('#have_news').load('auto_load_news.php').show("slow");
 $('#have_news').html(reply).show("slow");

// talvez ...
while($row = $result->fetch()){
if($row['idposta'] > $last){

Edited by HappyHippyHippo

IRC : sim, é algo que ainda existe >> #p@p

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.