Utilizing web-forms to gather data from a form and then transmit the data to the code-behind in order to forward it to an API. By clicking on a button, I trigger a JavaScript function that gathers the data and then sends it over to my aspx.cs file for communication with the API. The HTML code snippet for the button is as follows:
<button class="search btn" ID="btnSearch" onclick="searchApi(); return false;"><i class="fas fa-search"></i>Search</button>
This executes the searchAPI() function which successfully creates a concatenated string named SearchData. The corresponding Javascript code appears like this:
var searchString = JsonData;
var trimsearchString = searchString.replace(/,/g, '');
$.ajax({
type: "POST",
url: 'Default.aspx/GetApi',
data: searchString,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('success');
},
error: function (errordata) {
console.log(errordata);
alert(errordata);
}
});
The method GetAPI within my Default.aspx.cs script remains untriggered. Here's what the method looks like:
[System.Web.Services.WebMethod]
public static void GetApi(string searchData)
{...
While the success: function (data) signifies success, the associated code-behind method fails to execute. Any insights on what could potentially be missing would be greatly appreciated.