karthikeyan s
karthikeyan s

Reputation: 1

how to configure jquery ajax with asp.net?

$.ajax({
type: "POST",
contentType: "application/json;charset=utf-8",
url: "SaveAudiVideo.aspx/SaveData",
data: JSON.stringify({title: 'value1' ,songPath: 'value2' }),
dataType: "json",
success: function(data) {
$('lbltxt').text(data.d);
},
error: function(result) {
alert("error");
}
});

This is the code I have tried. I have seen lot of examples in the net everything resembles the same, but it is not working for me. Is there any other thing to configure and include into my project before running this ajax script? like JSON(newtonsoft) asp.net ajax?

Upvotes: 0

Views: 47

Answers (1)

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Firstly

Add jquery link to your master page

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

Secondly

You are giving path like

SaveAudiVideo.aspx/SaveData

It seems that you are trying to access aspx page method. but if you don't configure your aspx like web api it won't work.

To make your .aspx page mathod like web api

Try This

[System.Web.Services.WebMethod]
public static string SaveData(string title,string songPath)
{
    return title+" "+songPath;
}

There more info here

here is another example you can try this.

Upvotes: 1

Related Questions