2

i am using ajax jquery method to pass value to server, but my problem is i am using some value with single quote ' and it's give me error ,

ClientManager = "Client's Manager " <== here i am passing value with ' (single quote)


  data: "{projectSoid': '" + ProjectId + "','startDate': '" + StartDate + "','endDate': '" + EndDate + "','clientManager': '" + ClientManager + "'}",

and ajax jquery method, Error give me error :-

Message: Invalid object passed in, ':' or '}' expected. ........

infect i want all fields allows with ' (single quote)

what's the best soulution to passdata as jQuery Ajax Methods's data : {

6
  • try escaping, like, "Client\'s Manager" Commented Mar 8, 2013 at 11:38
  • huh! is it solution? Dear , i am not expecting that end user type client name as : Client\'s Manager" Commented Mar 8, 2013 at 11:40
  • Who the hell said that end user types that in. Bye, dear Commented Mar 8, 2013 at 11:42
  • you can use encodeURIComponent to encode this single quote. Commented Mar 8, 2013 at 11:43
  • data: {projectSoid: ProjectId ,startDate: StartDate ,endDate: EndDate ,clientManager: ClientManager} Commented Mar 8, 2013 at 11:44

1 Answer 1

2

Try defining an object literal, instead of concatenating a String.

data: {
        "projectSoid": ProjectId,
        "startDate": StartDate,
        "endDate": EndDate,
        "clientManager": ClientManager
      },
          //other entries
Sign up to request clarification or add additional context in comments.

5 Comments

If he want it as a string JSON.stringify({...})
@ArunPJohny That would also work, but with the object literal you avoid all of the concatenation.
give me error like : Message: Invalid JSON primitive: projectSoid
@NestorC could you post the full jquery Ajax code? I may be wrong, I'm assuming your using .Net after some research, I was posting this answer from a java perspective. encosia.com/asmx-scriptservice-mistake-invalid-json-primitive

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.