How to return some value from asp.net page that is called using jQuery Get() method ? The get method is given below and i want the alert() should display the returned value.
The get() calls "result.aspx" page that return a string and that string i want to show in alert().
$.get("result.aspx",
{
name: "Donald Duck",
city: "India"
},
function (result, status, xhr) {
alert(result);
}
);
The result.aspx code is:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadReturn();
}
}
void LoadReturn()
{
string name = Request.QueryString["name"];
string city = Request.QueryString["city"];
string returnValue="Hello Mr."+ name + " who lives in " + city;
//How to return value of returnValue to the jquery get() function.
}
How to return value of returnValue to the jquery get() function ??
Update I tried the response.write(). It is able to return the data to jquery get() method.
Response.Write(returnValue);
Only problem is that it is also sending me the full HTML of the result.aspx page. Which i don't want.
How can i prevent the unnecessary HTML from reaching the jquery get() method?
WebMethodor a separate .svc webservice file. aspx pages are designed to serve a whole HTML page from a full page load, not fragments of HTML or JSON to an ajax call. This tutorial gives a nice simple example using aWebMethod. aspsnippets.com/Articles/…