Every time I attempt to send Ajax jQuery parameters in a POST request with MVC 5, I am met with receiving NULL values

When attempting to send the subscriberemail parameter to the action result in the controller using AJAX jQuery parameters, I am consistently receiving a null value. Here is the code snippet:


$("#button-subscribe-newsletter").click(function () {
    debugger
    if ($('#subscribe_form_email').val().length > 0)
    {
        if (isEmail($('#subscribe_form_email').val())) {

            var obj = {};
            obj["subscriberemail"] = $("#subscribe-form-email").val();

            $.ajax({
                dataType: "json",
                url: '/CreateSubscribe/Create',
                type: 'post',
                data: obj,
                success: function (d) {
                    if (d.val == true) {
                        $("#subscribenewsletterform").hide();
                        $("#Success-Message").show();
                        $("#Failed-Message").hide();
                        $("#Null-Message").hide();
                    }
                    else {
                        $("#Failed-Message").show();
                    }
                }
            });
        } else {
            $("#Null-Message").show();
        }
    } else {
        $("#Null-Message").show();
    }
});

This is the corresponding controller for the above JavaScript code:


public class CreateSubscribeController : Controller
{
    // GET: CreateSubscribe
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult Create(string subscriberemail)
    {
        var keys = new Dictionary<string, string>() {
            { "Email",subscriberemail }
        };

        if (SitefinityWebApp.Helpers.SitefinityHelper.CreateSubscriberAndAddToMailingList(MailList.Maillist, subscriberemail))
        {
            SitefinityWebApp.Helpers.SitefinityHelper.SendEmailByTemplate(EmailTemplates.SubscribeEmail, subscriberemail, keys);
            return Json(new { val = true }, JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(new { val = false }, JsonRequestBehavior.AllowGet);
        }
    }
}

If you have any advice or suggestions on how to resolve the issue of receiving a null value for the subscriberemail parameter, please share.

Answer №1

To improve your code, make the following adjustment in your jQuery script:

obj["emailSubscriber"] = $("#subscription_email_form").val();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing React Redux to handle nested AJAX requests

Currently, I am developing some demoware and have encountered a situation where I need to make two AJAX calls. The first call is to check the last modified date and determine whether data from the second call should be fetched or not. Although this metho ...

Is there a way to use AJAX for transferring a value?

I am looking to transmit a value to a php-script (servo.php) that will then write the received data in a file (/dev/servoblaster). The script section of my HTML file (index.html): <script> function tiltt() { var tilt = document.getElementById("tilt ...

Why is my PHP function not able to properly receive the array that was sent to it via Ajax?

After retrieving an array through an ajax query, I am looking to pass it to a PHP function for manipulation and utilization of the elements at each index. The PHP function in question is as follows: class ControladorCompraEfectivoYTarjeta { public fu ...

Utilize JavaScript to parse JSON containing multiple object settings

After receiving the server's response, I am looking to extract the "result" from the JSON data provided. This is my JSON Input: { "header":{ "type":"esummary", "version":"0.3" }, "result":{ "28885854":{ "uid":"28885854", "pub ...

Working with jQuery: Creating multiple lightboxes using the same jQuery code

Is there a way to create a universal lightbox with the same code for all lightbox functions on the page using JQuery? $(document).ready(function() { $('.lightbox').click(function() { $('.backdrop, .box').animat ...

assistance required with jeasyui ajax

I am currently working with jeasyUI and attempting to create a tree-style file grid. My code is functioning correctly in terms of retrieving items from my MySQL database, displaying them, and allowing for drag and drop functionality. However, I am strugg ...

When utilizing jQuery events, ensure to pass along parameters when context is changed

I am working with the following simple code: app.Modules.myModule = { init: function(){ this.bindEvents(); }, bindEvents: function(){ app.Events.on('user:added', this.userAdded.call(this)); this.username = $( ...

Exploring cross-domain loading and AJAX with JQuery

My process for loading items on is as follows: Starting with JQuery via Google API Next, I load two global functions from another domain: loadcrossdomain (using getJSON via query.yahooapis) and a simple function for URL parsing Inclusion of Googl ...

Error: Papa is not defined. The file was loaded from the CDN in the header section

I have integrated the cdn hosted lib for PapaParse in my HTML header. However, when I execute my JavaScript file and it reaches the function where I call Papa.unparse(data); It throws an error stating that Papa is undefined. This has left me puzzled as I h ...

Remove a div element with Javascript when a button is clicked

I am working on a project where I need to dynamically add and remove divs from a webpage. These divs contain inner divs, and while the functionality to add new divs is working fine for me, I'm facing some issues with removing them. The code snippet b ...

Asynchronous AJAX processing in Ruby helper functions

I need assistance with running an asynchronous ajax request in a Ruby on Rails helper method. Specifically, I am trying to use remote_function: remote_function :url => { :action => "draw_graph" }, :after => "do_something_after_ajax_is_done()" } ...

I am puzzled as to why the JSON response is visible in the browser but cannot be forwarded to the Ajax callback function, causing the page to remain on the initial request page

Currently, I am in the process of developing a web application that utilizes AJAX and servlet. My main focus right now is creating a functional login page for the application. Although the servlet successfully generates a response in JSON format, the issu ...

What is the best way to obtain the output of a JavaScript function on the server side?

I'm dealing with a JavaScript function that returns an array in this particular format: <script type="text/javascript"> function looping() { var column_num = 1; var array = []; $("#columns ul").not(" ...

Creating an element that remains fixed once it reaches a distance of 50px from the top of the screen

Hey there! I'm working with an html div element that currently scrolls along with the page, but I was wondering how I can make it become fixed once it reaches a distance of 50px from the top of the screen. Any ideas on how to achieve this? Just to pro ...

Passing variables from AJAX response to PHP using a passthru function

In my PHP file, I have implemented a functionality where certain checkboxes are checked and upon clicking a button, a JavaScript file is triggered. The JavaScript code snippet used is as follows: $.ajax ({ type: "POST", url: "decisionExec.php", ...

Leveraging jQuery plugins within an AngularJs application

I am currently trying to implement the tinyColorPicker plugin from here in my Angular app, but I am facing difficulties with it. An error message keeps appearing: TypeError: element.colorPicker is not a function In my index.html file, I have included th ...

Is it possible to retrieve a JSON response by making a jQuery.ajax request to an appengine URL?

Attempting to retrieve response data via ajax from the following URL: http://recipesid.appspot.com/api.user?method=user.query&[email protected] Encountering issues when trying to run the code. Please assist in resolving this problem. $.ajax({ ...

Sending an array or list of files from AJAX to the Controller

I have a task to upload multiple files and pass them to my Controller's Action. The current code is functional, but I feel there could be room for improvement as it's somewhat manual. I need to display file upload elements based on the number of ...

Make sure to refresh the model using an Ajax request in Spring MVC

I have a page where I use AJAX to insert data into my database. On that same page, I display a table of records that are inserted. Each time I add a new record, I want to update the content of the table. Here is what I have implemented: @RequestMapping(va ...

Utilizing latitude and longitude coordinates for generating visual representations of user location data

I am working on a mobile application that allows users to capture and save information about their favorite monuments. When a user takes a photo of a monument, the app instantly records the latitude and longitude values as separate entities. Afterwards, t ...