简体   繁体   中英

Javascript Ajax call to asp.net webmethod, Internal server error

I've got a piece of JavaScript on a webpage that allows a user to scan in serial numbers and then it should send those to a webmethod where a database records it and a txtfile gets made.

It doesn't matter what's in the webmethod, because the code never runs. (Even removing the entire method and just make it change a bool to true as an example returns the same error). Here is the Js:

function sendingReady() {

  saveSerialNumbers();

  var employeeNr = document.getElementById("userCode").textContent;
  var productNr = document.getElementById("productCode").textContent;
  var cnt = {
    employeeNumber: employeeNr,
    productNumber: productNr
  };
  $.ajax({
    type: "POST",
    url: "WebServices.asmx/sendingReady",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify({
      'cnt': cnt
    }),
    success: function() {
      console.log("Success sendingReady")
    },
    error: function() {}
  });
  var succes = "succes";
  localStorage.setItem("SuccesVerzenden", succes);
}

function saveSerialNumbers() {

  var scannedserials = [];
  var errorchoises = [];

  var Table = document.getElementById("SerialListContainer");
  var rowLength = Table.rows.length;

  for (i = 0; i < rowLength; i++) {
    var row = Table.rows[i];

    var serialnumber = row.childNodes[0].textContent;
    scannedserials.push(serialnumber);

    var errorChoice = row.childNodes[1].childNodes[0].value;
    errorchoises.push(errorChoice);
  }

  var cnt = {
    serialNumber: scannedserials,
    sendingErrorcode: errorchoises,
    personalNumber: document.getElementById("userCode").textContent,
    productNumber: document.getElementById("productCode").textContent
  };
  $.ajax({
    type: "POST",
    url: "WebServices.asmx/createSendingCeetisFile",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    data: JSON.stringify({
      'cnt': cnt
    }),
    success: function() {
      console.log("Success saveSerialNumbers")
    },
    error: function() {}
  });

}

To top function works, I get the "success SendingReady" message in my log. But the bottom function, called by the top one, does not. I've tried everything from sending the data as 4 separate instances, to changing the options in the Ajax call, to changing the recipient webmethod. This is said webmethod:

[System.Web.Services.WebMethod]
public void createSendingCeetisFile(SendingErrors cnt)
{
//unimportant code that doesn't ever run anyway; 
}

with sendingErrors being:

public class SendingErrors
{
    public string[] serialNumber { get; set; }
    public string[] sendingErrorcode { get; set; }
    public string[] dollies { get; set; }
    public string personalNumber { get; set; }
    public string productNumber { get; set; }
}

Dollies isn't being used yet. I'm using IIS and I haven't found any way to debug the server-side; All the IIS logs show is a generic '500' with no further detail.

I'm really hoping I'm missing something obvious, but after trawling through these forums and other sites looking for an answer for slightly over a day I'm kind of losing hope.

Thank you M Adeel Khalid and mplungjan for your help. Though none of your responses was the direct answer the understanding it lend me gave me the idea to try and remove the function from within the other function and just call it directly from the button. this did the trick. I'm still getting an odd error, but the function does everything it is supposed to, saving the records to a database and writing it up in a file for use in a different program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM