Shukhrat Raimov
Shukhrat Raimov

Reputation: 2247

How to make an ajax call without callback

I am using $.ajax() to send the data to a controller action that saves the data to a database. And after the data is saved, I don't need any callback function to the $.ajax(). I just want to render another view. But since this $.ajax() requires to get something back, I receive a parser error.

Here is my ajax call:

$("#submit_btn").click(handleSubmit);
 function handleSubmit(e) {
        alert("Clicked!");
        e.preventDefault();
        var ans = [];
        for (var i = 0; i <= id_txt; i++) {
            ans.push($("#_addText" + i).val())
        }
        var options = {};
        options.url = "/Technique/Steps";
        options.type = "POST";
        options.data = JSON.stringify(
        {
            Id: $("#Id").val(),
            Poradi: $("#Poradi").val(),
            TechniqueId: $("#TechniqueId").val(),
            Answers: ans
        });
        options.contentType = "application/json";
        options.dataType = "json";
        options.error = function (jqXHR, status, err) { alert(status + "from AJAX"); };
        $.ajax(options);
    };

Is there any way to say this method, that I do not need anything back, so please dont expect

return JSON(someobject)

from a controller action.

Upvotes: 0

Views: 3179

Answers (1)

jfriend00
jfriend00

Reputation: 707436

Change:

options.dataType = "json";

to:

options.dataType = "text";

Since the text format requires no processing by jQuery when the response arrives and you aren't looking for a return value anyway, there's little room for a parsing error with the dataType set to "text".

Upvotes: 1

Related Questions