Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6731621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:33:03+00:00 2026-05-26T10:33:03+00:00

I have the following ajax email submit routine on my ASP.NET WebForms web site:

  • 0

I have the following ajax email submit routine on my ASP.NET WebForms web site:

A page provides a user with an input dialog, where he enters data.
A data is packed into a json like this:

        var name = $("[id$='clientName']");
        var phone = $("[id$='clientPhone']");
        var serviceType;
        var serviceCost;

    $("#SubmitOrder").click(function () {

        var currName = name.val();
        var currPhone = phone.val();

        var json = "{'ClientName':'" + escape(name.val()) + "','ClientPhone':'" + escape(phone.val()) + "','ServiceType':'" + serviceType + "','ServiceCost':'" + serviceCost + "'}";
        var ajaxPage = "/sendmail.aspx?Send=1"; 
        var options = {
            type: "POST",
            url: ajaxPage,
            data: json,
            contentType: "application/json;charset=utf-8",
            dataType: "json",
            async: true,
            success: function (response) {                  
                $("#ResMsg").html(response);
            },
            error: function (msg) { alert("failed: " + msg); }
        };

        $.ajax(options);
    });

and is sent to a sendmail.aspx for procession. sendmail.aspx is just a webforms page that, when debugged, works just fine. It receives and parses the JSON correctly, then initiates an async mail sending routine.

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            SendMail();
    }

private void SendEmail()
    {
        //Bunch of parsing and mail sender init

        mailSender.MessageSent += new MessageSentEventHandler(OnMessageSent);
        //Here we have subscribed to an async event that occurs when mail sender is done.

        // Other unimportant stuff

        mailSender.SendMessage(settings["mail.feedback.to.name"], settings["mail.feedback.to.email"], settings["mail.feedback.subject"], body);
    }

void OnMessageSent(object sender, MessageSentEventArgs args)
    {
        if (args.Status == MailSentStatus.Sent)
        {
            Response.Write("Everything is fine"); 
        }
        else
        {
            Response.Write("Oops. Error!"); 
        }
    }

The problem:

On my client page, whenever the response is received from the mail sender I get a

failed: [object Object] message box.

Apparently my error: method gets executed instead of success:. But the mail sender sends messages just fine.

What is the correct way to respond to a jquery .ajax() call from an ASP.NET? What am I doing wrong in my case?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:33:04+00:00Added an answer on May 26, 2026 at 10:33 am

    You told $.ajax to expect dataType: "json", so it’s trying (and failing) to parse the returned HTML as JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
i have the following references to jquery on my page: <link href=http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css rel=stylesheet type=text/css/>
I have the following Javascript libraries loaded for my page. <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js></script> <script
I have the following JQuery to submit a contact form with jquery ajax. This
I have the following javascript: $.ajax({ type: "POST", dataType: "json", url: "/Home/Submit", data: {
I have the following piece of code: // setup the AJAX request var pageRequest
I have the following HTML structure being returned from an AJAX request... <th scope=col
i have the following javascript to post a form through ajax without refreshing the
I have the following simple jquery snippet $(document).ready(function () { $.ajax({ url:myjson.json, dataType: 'json',
I have the following js code: var ret; $.ajax({ type: 'GET', url: '/Pay/Build64/', dataType:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.