Problem with jQuery.ajax php

0

Well, I have a problem that I do not know what to do. I've tried to do everything but nothing. It is the following I am doing a php chat but this is giving an alert () error:

  

ERROR!

 jQuery(function(){
    jQuery('body').on('keyup', '.chat_msg', function(e){
        if(e.which == 13){
            var text = jQuery(this).val();
            var idS = jQuery(this).attr('id');

            jQuery.ajax({
                type: 'MPOST',
                url: 'sys/submsg.php',
                data: {mensagem: text, de: idS},
                success: function(retorno){
                    if (retorno == 'ok') {
                        jQuery('.chat_msg').val('');
                    }else{
                        alert('ERROR!');
                    }
                }
            });
        }
    });
});

OTHERS SCRIPT sys / submsg.php

<?php
    if(isset($_MPOST["mensagem"])) { 
        @include_once('BD.class.php');

        $mensagem = utf8_decode(strip_tags(trim(filter_input(INPUT_POST, 'mensagem', FILTER_SANITIZE_STRING))));
        $de = (int)$_MPOST['de'];
        $url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$de); 
        $content = json_decode($url, true);

        $name = htmlspecialchars($content['response']['players'][0]['personaname']);
        $avatar = $content['response']['players'][0]['avatar'];
        $urlName = $content['response']['players'][0]['profileurl'];

        if($mensagem != ''){
            $insert = BD::conn()->prepare("INSERT INTO 'chat' (name,avatar,url,mensagem) VALUES (?,?,?,? ");
            $arrayInsert = array($name,$avatar,$urlName,$mensagem);
            if($insert->execute($arrayInsert)){
                echo 'ok';
            }else{
                echo 'off';
            }
        }
    }
?>

It is as if submite.php did not have to give pk the return is not receiving anything Thanks to anyone who can help me:)

    
asked by anonymous 16.05.2016 / 00:24

1 answer

2

Two changes:

  • Uses the POST pro request method because jQuery uses GET when it does not have this parameter defined
  • I changed the query, closing VALUES() , missing the last ) .

JS:

jQuery(function(){
    jQuery('body').on('keyup', '.chat_msg', function(e){
        if(e.which == 13){
            var text = jQuery(this).val();
            var idS = jQuery(this).attr('id');

            jQuery.ajax({
                type: 'POST',
                url: 'sys/submsg.php',
                data: {mensagem: text, de: idS},
                success: function(retorno){
                    if (retorno == 'ok') {
                        jQuery('.chat_msg').val('');
                    }else{
                        alert('ERROR!');
                    }
                }
            });
        }
    });
});

PHP:

<?php
    if(isset($_POST["mensagem"])) { 
        @include_once('BD.class.php');

        $mensagem = utf8_decode(strip_tags(trim(filter_input(INPUT_POST, 'mensagem', FILTER_SANITIZE_STRING))));
        $de = (int)$_POST['de'];
        $url = file_get_contents("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=".$steamauth['apikey']."&steamids=".$de); 
        $content = json_decode($url, true);

        $name = htmlspecialchars($content['response']['players'][0]['personaname']);
        $avatar = $content['response']['players'][0]['avatar'];
        $urlName = $content['response']['players'][0]['profileurl'];

        if($mensagem != ''){
            $insert = BD::conn()->prepare("INSERT INTO 'chat' (name,avatar,url,mensagem) VALUES (?,?,?,?) ");
            $arrayInsert = array($name,$avatar,$urlName,$mensagem);
            if($insert->execute($arrayInsert)){
                echo 'ok';
            }else{
                echo 'off';
            }
        }
    }
?>
    
16.05.2016 / 04:03