this way i am calling my server side code….my code as follows.
$(function () {
$('#btnSubmit').click(function () {
$.ajax({
type: "GET",
url: "MyPage.aspx?id=201/GetData",
data: {},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
}
,
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
return false;
});
});
i doubt i am getting error because url is wrong url: “MyPage.aspx?id=201/GetData”
i think it should be url: “MyPage.aspx?id=201”
2) i have another question that what different type of value can be set for dataType property of jquery ajax call.
dataType can be html or text? when dataType would be html then what would be right contentType? and the same way when
dataType would be text then what would be right contentType?
3) when dataType will be text or html then can i call my custom server side function like url: “MyPage.aspx/GetData”,
4) when dataType will be text or html then how to return data from server side function. then can i write code like
when datatype is text then do i need to return like below one
[System.Web.Services.WebMethod]
public static string GetData()
{
return "Hello";
}
[System.Web.Services.WebMethod]
public static string GetData()
{
response.write("Hello");
}
when datatype is html then do i need to return like below one
[System.Web.Services.WebMethod]
public static string GetData()
{
return "<div>Hello</div>";
}
[System.Web.Services.WebMethod]
public static string GetData()
{
response.write("<div>Hello</div>");
}
do i need to set response.content type.
please guide in detail…….thanks
The answers
Your ajax call should be like this
You are calling GetData on MyPage.aspx. Why should you worry that it has querystrings and hashtags? So, please do not pass the querystring.
Have you read this once? http://api.jquery.com/jQuery.ajax/ Check the section dataTypes.
Why don’t you try and find that for yourself? Wont take more than 10 minutes.
P.S: Don’t worry about the downvotes. The problem is that this question is a valid one at forums, but not here. Thats because, this is not exactly a forum, this is a QA site.
Read: https://stackoverflow.com/faq#dontask