I'm struggling with a JavaScript script that makes an AJAX call to a service:
$.ajax({
type: "GET",
url: ServiceAddress + "/Service.aspx?action=LoadRandomImagePath&userID=" + USER_ID,
success: function (result) {
if (result.LoadRandomImagePathResult.ID != 0) {
//something
}
Here is what happens when the Service.aspx is called:
Response.Write(svc.LoadRandomImagePath(int.Parse(Request.QueryString["userID"])));
The svc.LoadRandomImagePath method returns JSON data and writes it to the Response.
However, my issue arises when I receive the result on the JavaScript side - it includes the full code of the Service.aspx page:
{JSON HERE}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><title> </title></head> <body> <form method="post" action="Service.aspx?action=LoadRandomImagePath&userID=18" id="form1"> <div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE2MTY2ODcyMjlkZLyq7A39QtHu0Ngft6E/6ZwTABk29noGDsoP6FKK6UIo" /> </div> <div> </div> </form> </body> </html>
My goal is to only get the JSON response without any additional page code. Is there a way to achieve this?