I have a JSON object like so:
var newContact = {"contact_name":"Joe","contact_cell_phone":"4651354"}
And I need to pass it through to C# ASP backend using Angular $http.post such as:
$scope.Add = function (newContact) {
// I am passing in this string variable "newContact_string", not the function param "newContact"
var newContract_string = JSON.stringify(newContact);
$http
.post('Default.aspx/AddDb_contact', { newContact_string: newContact_string })
.success(function (data) {
console.log("New contact was added with id: " + data.d);
})
.error(function () {
console.log("An error occurred adding the new contact.");
});
};
However, I am hit with this error in the JS console, specifically referring to this line of code:
ReferenceError: newContact_string is not defined
>> $http.post('Default.aspx/AddDb_contact', { newContact_string: newContact_string })
My C# backend code is never reached:
[WebMethod]
public static object AddDb_contact(string newContact_string)
{
return newContact_string;
}
Perhaps it is a syntax error? How would I go about AJAXing the Angular way?