2

i'm creating my own MVC Framework. I have a basic form in my view

<form action="?" method="post" >
    <input type="hidden" name="envoie" value="envoie" />
    <?php dico('INSCRIPTION_NOM'); ?><input id="name" type="text" name="name" /><br />
    <?php dico('INSCRIPTION_EMAIL'); ?><input id="email" type="text" name="email" /><br />
    <?php dico('INSCRIPTION_PWD'); ?><input id="pwd" type="password" name="pwd" /><br />
    <input type="button" value="<?php dico('INSCRIPTION_SINSCRIRE'); ?>" onclick="verifForm(document.getElementById('email').value);"/>
</form>

when I clock on the button they have a javascript function like that :

function verifForm(email) {
    var url ="?c=Inscription&a=VerifForm&email="+email;
    $.get(url, function(data){
        alert('resultat == '+data);
    });
}

Inscription was my controllers and VerifForm an method of the controller. email was the value of a input.

The Php function was :

public function actionVerifForm() {
        echo "OK";
}

When i click on the button i have all the code of the page on my alert but i only want the message "OK".

Thanks for helping me

2
  • 1
    what do you mean by i have all the code of the page on my alert? you mean your PHP code is alerted? Commented Jan 16, 2012 at 22:13
  • You can test my appl on iftp.axioweb.fr/?c=Inscription&a=Formulaire for seeing the problem of the alert message Commented Jan 17, 2012 at 21:31

1 Answer 1

1

what you are doing is AJAX, am i right? the data parameter IS your result. AJAX returns the echo-ed page as a string. if you mean to place it in the page, try jQuery .html() or .text() for a text only, escaped version.

function verifForm(email) {
    var url ="?c=Inscription&a=VerifForm&email="+email;
    $.get(url, function(data){
        $('#container-id-here').html(data); //html insert
        $('#container-id-here').text(data); //text insert
    });
}

and in your PHP, since you are doing AJAX, you should only echo what you need returned, and not the whole HTML mark-up (which means no <html><head>...</head></html>

Sign up to request clarification or add additional context in comments.

12 Comments

i'm gonna test the .html and .text but i need my data in an alert.
Work if i want my data on div but i need the data on my alert
it's working properly actually. the problem is that your PHP is not just echoing the result, but is including the HTML mark-up as well! the php should only echo what you want in order to return what you need.
if you are creating an MVC and this is your default view, you should also create an additional "ajax-only" view, with no additional HTML mark-up.
it's not my default view it's a registration view. What i need un my ajax-only view?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.