0

I am trying to request an XML from a .NET service which I need to enter in DB through a Classic ASP code. I am using two AJAX requests to do same.

Through 1st I am calling the .NET code and receiving the XML. In second AJAX I am sending back the XML to an ASP page which enters the same in DB.

here is AJAX Code

$(document).ready(function () {
$.ajax({
    crossDomain: true,
    type: "GET",
    cache: false,
    contentType: "xml/text; charset=utf-8",
    async: false,
    url: --..Some .NET url...--,
    dataType: "text",
    success: function (result, status, xhr) {
        //var xml_serializer = new XMLSerializer();
        //var abc = xml_serializer.serializeToString(result);
        var xml = encodeXml(result);
        alert(xml);
         $.ajax({
         type: "POST",
         data :  { xmlsent: xml },
         url: --ASP URL--,
         contentType: "text/xml; charset=utf-8",
         dataType: "text",
         success: function (result1, response , xhr) {
            debugger;
            alert(xml);
            alert(result1);
         },
         failure: function (response) {
            debugger;
            alert(response);
         }
     });


    },
    error: function (xhr, status, error) {
        alert("eRROR");
        alert(error);
    }
}); 
}); 

My Classic ASP Code

Dim cnn, sql
Dim UserID
Set cnn = Server.CreateObject("ADODB.connection")
cnn.Open cConnectionString        'Connection string is set already
UserID= Request.Form("xmlsent") & "abc5"
sql=""
sql = sql & " UPDATE tablename set columnname='" & UserID & "' Where colid = 123"
cnn.Execute(sql) 
Response.Write UserID

Now update in Db works' that means my ASP code is being called but the value which is being set in DB is just "abc5" that means that Request.Form("xmlsent") is null (this is the main issue)

Also 1st alert with XMl works fine and I am able to see XML in an alert box. Even second XMl worksi.e. my ASP page is also called. Db update is done but with null append with "abc5"

Note: the Ajax code is in the different page as from ASP code.

always-a-learner
  • 3,671
  • 10
  • 41
  • 81
  • Any change if you dont specify the `contentType: "text/xml; charset=utf-8"`? – Flakes Sep 08 '17 at 11:22
  • Check how the POST data is being passed in the RAW HTTP request. [This question](https://stackoverflow.com/a/41900597/692942) should help you debug the `Request.Form` collection. Also bear in mind that setting `contentType: text/xml` means the POST request will expect an XML document as the request body, which I don't think you are sending. – user692942 Sep 08 '17 at 21:21
  • 1
    Thanks all for comments changing content type solved the issue. – user8546638 Sep 11 '17 at 06:12

0 Answers0