-1

Even my code works to pass value with ajax.I still want to transform data to json type then pass it to ajax,like this:

{"name":"test"}

and now data is like this below:

var data = {
            'name': $("#name").val()
        }

how can I get json? thank you for your answer!

2
  • What is the problem, exactly? You can just pass the variable as is to $.ajax(). Commented Aug 2, 2013 at 8:43
  • I know this~ and i just wanna have a try. Commented Aug 2, 2013 at 8:44

2 Answers 2

1

Here:

var jsonData = JSON.stringify(data);
Sign up to request clarification or add additional context in comments.

Comments

0
 var jsonString= JSON.stringify(obj);

kindly refer this link

How to create JSON string in JavaScript?

Comments

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.