1

I am new to jquery ,so i need some help to make a request to server with post.

Why i have chosen $.post is i have large ammount of data to pass to the server.

I have javascript variables like action="Next",resultData=""(this is the very large string). So how to pass this javascript varaiables to $.post?

Thanks.

2 Answers 2

2

Just use an object as $.post's optional second parameter, like this:

$.post("foo.html", { action: "Next", resultData: '...' }, function(html) {
    // success callback
});
Sign up to request clarification or add additional context in comments.

Comments

1

It's all defined in the man page for it $.post is just an alias of $.ajax. I would suggest using $.ajax instead just because you have more control and it's more maintainable in the long run.

$.ajax({
  type: 'POST',
  url: url,
  data: data,
  success: success
  dataType: dataType
});

You can either define data in it's var1=data1&var2=data2&var3=data3 string format, or as an object. I suggest using objects because it's eaiser to see and work with.

{
  "var1" : "data1",
  "var2" : "data2",
  "var3" : "data3"
}

4 Comments

Hi Thanks,if i use .ajax with post,i am not able to send large ammount of data within the query string,because there is limitation on length of thurl.i converted my js string using json.stringify and trying to pass as url,but still no luck.please suggest me ,which one i have to select and how to send large ammount of data with jquery
Huh? You don't send data in the URL of a POST request, that's a thing you do with GET. $.post and $.get are aliases of $.ajax so anything you do with them you can do with $.ajax.
Yes i able to resolve my issue now,by passing data as key value pairs instead of sending data as query string.Thanks.
You should click "accept answer" if this solved your question.

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.