1

I have been working on a web application, I used to work in PHP with jQuery and it works well, but now I have moved on it, but it's not working fine with the same logic of jQuery which I have used for posting a form. May be ASP has some special and more easier way for page posting and getting response without page refresh, does anybody know about that?

4 Answers 4

3

You can use jQuery post function with form serialize function to post a form without refresh,

$.post($("#formId").serialize(), function(data) {
  $('#result').html(data);
});
Sign up to request clarification or add additional context in comments.

4 Comments

yes i used the similar code for php, but in that we must specify target: postFile.php etc, but what target will be used to receive in that, as data is received on codeBehind file.
You can call asp net web service . See this example, dotnetslackers.com/articles/ajax/Using-jQuery-with-ASP-NET.aspx
In php, we dont need any web service, then why in asp? even its easier than php.
You can stille post to a aspx page -: codeproject.com/KB/ajax/AjaxJQuerySample.aspx
1

You can use $.ajax.

For example:

$.ajax({
  type: "POST",
  url: "/some/url",
  data: "name=John&location=Boston",
  dataType: "json",
  success: function(msg){
    alert( "Data Saved: " + msg );
  }
});

3 Comments

Please give some example instad of /some/url, i mean would we post the variables to example.cs page, or example.asp, i am not getting it, migrated from php to asp. Also let me know, where we would place the receiver file.
Take a look at this blog post as it gives a good example of what is possible with a web service - encosia.com/2011/04/13/… If you don't want to use a web service your url can easily be another aspx page or an ashx generic handler and you can pick up your params via the request.form
Yes i dont wana use any webservice for these taks, as i am building a very large application and a lot of work is required to be done, so i dont wana involve in another complex thing. Let me know if you know any forum having the example of aspx page in target.
1

See the following link:

http://encosia.com/2008/05/29/using-jquery-to-directly-call-aspnet-ajax-page-methods/

Comments

0

Don't avoid a web service just because it sounds complicated; in ASP.NET it's not complicated at all to set up an endpoint to communicate via JSON*. In fact, if you use "page methods", you can define the service method inside your ASPX page's code behind.

Whatever you do, avoid calling an ASPX page directly for JSON like you might in PHP. In ASP.NET, requests to ASPX pages run through a request pipeline, instantiate an instance of the Page class, and run through the Page's life cycle. All of that processing is targeted toward requests that are handling server-side events and building an HTML document based on ASP.NET web controls, user controls, etc - a process which is not desirable when you just want some lightweight JSON communication.

(*) There's an update coming soon that will fixes WCF for the most part, but do avoid WCF for the time being. For what you're trying to do, ASMX works well and is vastly less complex than WCF.

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.