So I am working on an AJAX call to a PHP script which validates the
data submitted in a form.  My question concerns the best way to get
the data from PHP back to the jQuery script.  Should the dataType
field be html or script?  I tried html and I know I could parse out
what I need, but in the documentation it says script runs the code as
a javascript script, but I'm not sure of the scope of this script.  I
tried setting a variable name in the script and changing a global
variable value, but I saw no change when I displayed the value with
alert().  Am I missing something?

Code below:

$.ajax({
                        type: "POST",
                        url: "/register/index.php?action=validate",
                        data: "email="+ email + "& pass1=" + pass1,
                        dataType: "script",//"html",
                        complete: function (XMLHttpRequest, textStatus) {
                                alert("complete");
                        },
                        success: function(del){
                                alert("success");
                                alert(del);
                                alert(email);
                                $("#email").addClass("error");
                                /*$('form#submit').hide();
                                $('div.success').fadeIn();*/
                        },
                        error: function (xhr, desc, exceptionobj) {
                                alert("error");
                                //alert(xhr.responseText);
                                alert(exceptionobj);
                        }
                });

I can make the PHP file return whatever I want.  What is the best in
this situation?

Thanks!

Reply via email to