2

I want to make a request to asp.net page using jQuery.get().

How should the Url format be, and how do I get the parameters which I sent with the data?

I tried like this:

$.ajax({
    type: "POST",
    url: "sendEmail.php",
    data: "{name:'" + name + "', message:'" + msg + "', mailTo :'" + to + "' }",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function () {
        $('#email_form').html("<div id='message'></div>");
        $('#message').append("<p>We will be in touch soon.</p>")
            .hide()
            .fadeIn(1500, function () {
            $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
    });
});

but i want to make a call in asp.net.

1
  • FYI, You are missing several }s and );s in your ajax request. So even if thats what you wanted to do, it wouldn't work. Commented Feb 5, 2012 at 19:35

3 Answers 3

2

jQuery.get() - Load data from the server using a HTTP GET request

documentation - http://api.jquery.com/jQuery.get/

$.get(
   // your aspx page
   "yourpage.aspx",

   // object literal used to populate query string
   { param1: "foo", param2: "bar" },

   // capture response in callback
   function(data){
     alert("Results: " + data);
   }
);

To access the parameters from the Code-Behind use:

HttpContext.Current.Request.QueryString["param1"].ToString();

or more succinctly:

Request.QueryString["param1"].ToString();

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

1 Comment

@EnesCanÇetiner just updated my answer to include the server-side snippet.
2

If you want to use get method try this.

$.get( "AspxPage.aspx", {
             name:  name, 
             message: msg, 
             mailTo : to 
          },
          function(response) {
            $('#email_form').html("<div id='message'></div>");
            $('#message').append("<p>We will be in touch soon.</p>")
            .hide()
            .fadeIn(1500, function() {
               $('#message').append("<img id='checkmark' src='images/check.png' />");
          }
);

Comments

0

Try this:

var data = {name: name , message: msg , mailTo : to };
$.get("sendEmail.aspx", data, function(response)
{
     $('#email_form').html("<div id='message'></div>");
     $('#message').append("<p>We will be in touch soon.</p>").hide().fadeIn(1500,function()      
     {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
     }
});

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.