amit patel
amit patel

Reputation: 2297

How can i pass NULL value in ajax jquery call?

Is there any way to handle null value when doing Ajax Call?

 $.ajax({
            type: "POST",
            url: "Login.aspx/SaveFacebookAutoSignUp",
            data: "{ 'Name':'" + rows[0].name + "', 'EmailId': '" + rows[0].email + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                alert("You have successfully sign in.");

            }
        });

This is saving "null" value in my DB for EmailId when it is not fetch from other page?

I want to save "NULL" (DB default NULL allow) in DB when it is not having any value?

What is the way to do so?

Upvotes: 2

Views: 18591

Answers (2)

Fabrice
Fabrice

Reputation: 3100

You can use undefined instead of null, as in the following example:

data: {
  valueTrue : true,
  valueFalse: false,
  valueNull : undefined
}

Upvotes: 4

BNL
BNL

Reputation: 7133

Pass in the value null NOT surrounded by quotes.

{
    "id": "1234",
    "nullableValue": null
}

I'd suggest not composing your json string manually, create an object then use a function call to convert it to json. In some cases you can just pass the object to the ajax call.

Upvotes: 0

Related Questions