Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

returning message within data from ajax post

           $.ajax({
                type: "POST",
                url: passUrl + "/RTOSaveJsonData",
                contentType: 'application/json; charset=utf-8',
                data: JSON.stringify(DTO),
                dataType: "json",
                async: false,
                success: function (data, textStatus, xmlHttpRequest) {
                    alert('success ');
             alert(data);
                    $("#postResults").html(data);
                },
                error: function(xhr, textStatus, error){
                console.log(xhr.statusText);
                console.log(textStatus);
                console.log(error);
                }

Open in new window


In my webservice, I want to return a message as to if the result was a success or if an error was found. Evidently $.post includes a success callback but not one for errors (according to forum post I read). So I would like to display any errors in the alert or on the screen.

In the above, I want to display the value I return, which is a string value and I assume somewhere within "data" but I don't know how to get the value I returned from within "data" to display to the screen as an alert or displayed on the screen.

I did try the above alert(data); and it just returns Object object.
I tried this:
         $("#postResults").html(data);

and nothing displays in my div tag:
   <div id="postResults"></div>

My message might be something like this: "Failure: you must have a user name."  So it's pretty simple.

Any suggestions for how to get that message out of the data that was returned?

thanks!
ASKER CERTIFIED SOLUTION
Avatar of zephyr_hex (Megan)
zephyr_hex (Megan)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk

ASKER

Thanks for teaching me how to fish!!!
Best advice all day!