1

I would like to have an AJAX call with the following type,

$.ajax({
    url:"../..",
    data:{
    stringvar:$("..").val(),
    jsonobj:JSON.stringify({
    }),
    anotherstringvar:$("..").val()
    },
    type:"POST",
    content-type:"application/json"
    success:function(data){
    // do something with the data
    }
 });

How do I achieve this kind of requirement. As you find above, i have to pass normal string values along with the JSON data and i have to bind the same using ASP.NET MVC2 Model binder and JSONValueProviderFactory, which have in place.

1 Answer 1

1

You can create a simple JSON object and send it to the server:

var data = JSON.stringify(valuetobestringified);

var json = {
    "json": data,
    "anotherstringvar": $("..").val(),
    "anotherstringvar1": $("..").val()
}

$.post("../..",json,function(){
//response from the server.
});

You can find more information about jQuery here: http://api.jquery.com/jQuery.post/

And you can create a simple JSON object with this online editor: http://jsonlint.com/

Sign up to request clarification or add additional context in comments.

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.