Problem with distant server and json_encode


#1

Hello everyone !
I’m having an issue trying to communicate with my remote server.

I want to send informations to my database using $.getJSON or $.post with the json as a fourth parameter.

the problem is that when i click on my submit button nothing happens.

I’m new with AJAX and json stuff, so maybe there’s something i’m doing wrong.

here is my PHP script (stored on the server)

$chaine = '';
if( isset($_GET['chaine']) ){    $chaine = $_GET['chaine'];}

$retour = array(    
'chaine'    => strtoupper($chaine),    
'date'      => date('d/m/Y H:i:s'),
'phpversion'=> phpversion());
header('Content-type: application/json');
echo json_encode($retour);

The client code i’m using on the ionic app is the following :

<form id="form">
    <input name="chaine" type="text" id="chaine" value="Bonjour"/>
    <input type="submit" value="Envoyer" id="handle"/>
</form>

<div id="retour">
    <i>vide</i>
</div>

<script>

    jQuery(document).ready(function ($) {
        $('#form').submit(function (e) {
            // On désactive le comportement par défaut du navigateur
            // (qui consiste à appeler la page action du formulaire)
            e.preventDefault();

            // On envoi la requête AJAX
            $.getJSON(
                    'http://SERVERADRESS/script.php',
                    {chaine: $('#chaine').val()},
                    function (data) {
                        $('#retour').hide();
                        $('#retour').html('')
                                .append('<b>Paramètre en majuscule</b> : ' + data.chaine + '<br/>')
                                .append('<b>Date</b> : ' + data.date + '<br/>')
                                .append('<b>Version PHP</b> : ' + data.phpversion + '<br/>');
                        $('#retour').fadeIn();
                    }
            );
        });
    });

</script>

Any idea how to make this work ? Is there something i’m missing ?


#2

No one has an idea ? :frowning:


#3

This problem has nothing to do with ionic…
Do not know why you are asking this here…