Enes Can Çetiner
Enes Can Çetiner

Reputation: 71

How can i get parameters on jQuery.Get();?

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.

Upvotes: 2

Views: 640

Answers (3)

Alex
Alex

Reputation: 35409

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();

Upvotes: 2

ShankarSangoli
ShankarSangoli

Reputation: 69905

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' />");
          }
);

Upvotes: 2

Jason
Jason

Reputation: 11615

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' />");
     }
});

Upvotes: 0

Related Questions