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 8191367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:54:14+00:00 2026-06-07T03:54:14+00:00

I am trying to post data using ajax in jquery of json datatype. I

  • 0

I am trying to post data using ajax in jquery of json datatype. I am using json’s stringify method to avoid single quote but It is not doing so for one value but doing other value. I am confused. I tried using replace function also but no use.

Following is my jquery code,

$.ajax({
                    type: "POST",
                    url: "<%=ResolveUrl("~/QualityComplaintService.asmx") %>/DoesVariantExists",                    
                    contentType: "application/json; charset=utf-8",
                    data: "{categoryId: '" + category.val() + "', subcategoryId: '" + subcategory.val() + "', brandId: '" + brand.val() + "', variant: '" + variant.val() + "'}",
                    dataType: "json",
                    success: function(msg) {
                        var d = msg.d;
                        if (d == true)
                        {
                           alert("Variant already exists! Please choose another one.");
                           return false;
                        }
                        else
                        {
                        var parameter = {
                                            categoryId: category.val(),
                                            subcategoryId: subcategory.val(),
                                            brandId: brand.val(),
                                            size: size.val(),
                                            variant: variant.val(), 
                                            chkIsActive: chkActive
                                        };
                            $.ajax({
                                type: "POST",
                                url: "<%=ResolveUrl("~/QualityComplaintService.asmx") %>/RegisterVariant",                    
                                contentType: "application/json; charset=utf-8",
                                data: JSON.stringify(parameter),
                                dataType: "json",
                                success: function(msg) {
                                    __doPostBack('<%=btnAdd.ClientID.Replace("_", "$") %>','');
                                }
                            });
                        }                    
                    }
            });

When I run the above code, I can insert single quote in size field but when I insert single quote on variant field i get error. But are of same datatype. What can be the problem?

  • 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-06-07T03:54:17+00:00Added an answer on June 7, 2026 at 3:54 am

    In your first AJAX request you have the following line:

    data: "{categoryId: '" + category.val() + "', subcategoryId: '" + subcategory.val() + "', brandId: '" + brand.val() + "', variant: '" + variant.val() + "'}",
    

    which obviously should be replaced with JSON.stringify to avoid the horrible string concatenation which will break as soon as one of the parameters contains some special characters such as a single quote:

    data: JSON.stringify({ 
        categoryId: category.val(), 
        subcategoryId: subcategory.val(), 
        brandId: brand.val(), 
        variant: variant.val()
    }),
    

    Your second ajax call seems fine as you are properly using the JSON.stringify method.

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

Sidebar

Related Questions

I am trying to post some data with jQuery Ajax, but the parameters in
I'm trying to use jquery.Ajax to post data to an ASP.NET MVC2 action method
Im having trouble trying to post data correctly using jQuery/AJAX I have the following...
Trying to post JSON data to Spring controller.. Not working at all JSP Code:
Hi, I am trying to save data using web services, jquery and json. From
I'm trying to do some really basic AJAX using PHP & jQuery, but for
I'm trying to post some very simple data to a php file using jquery
I'm trying to call an asp.net method using jquery/ajax from a button click on
I'm trying to send post data between pages with Post. Not a form -
I'm trying to send an ajax request using jquery. From the tutorial, I try

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.