0

I am working with AngularJS with Classic ASP.

While I have create one simple form in classic asp and submit it through AngularJS HTTP POST mathod and on other side when I am trying to get POST variable value in another page I am getting a null value.

Actually, while calling the HTTP POST method I can see in browser network mode that data was sent to the given URL, but at the given URL page I am not able to retrieve the posted data.

Here is my code

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.js"></script>
</head>
<body>
<div ng-app="CallSiteVisitor" ng-controller="SessionAndVisitor">
  <form ng-submit="SaveData()" >
    <input type="text" name="firstname" ng-model="form.firstname">
    <input type="text" name="lastname" ng-model="form.lastname">
    <input type="submit">
  </form>
</div>
var app = angular.module('CallSiteVisitor', ['ngSanitize']);

app.controller('SessionAndVisitor', function($scope, $http) {
    $scope.form = {};

    $scope.SaveData = function() {
        $http({
            method  : 'POST',
            url     : '/XXXX.asp',
            data    : $scope.form,
            headers : { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }
        })

        .success(function(data) {
            if (data.errors) {
                $scope.errorName = data.errors.name;
                $scope.errorUserName = data.errors.username;
                $scope.errorEmail = data.errors.email;
            } else {
                $scope.message = data.message;
            }
        });
    };
});

Here I have try multiple way to get POST variable like

Response.Write request("firstname")
Response.Write request.Form("firstname")
Response.Write request.Form("form.firstname")

In all these cases I will get null value instead of textbox value.

  • The form data is posted as json, so you have to parse it as json in the action page. see: https://stackoverflow.com/questions/1019223/any-good-libraries-for-parsing-json-in-classic-asp – Flakes Mar 21 '18 at 07:07
  • @SearchAndResQ where does it say it’s posted as JSON? Only post I can see is in `SaveData()` and that sets the `Content-Type` header to `application/x-www-form-urlencoded`. – user692942 Mar 21 '18 at 07:39
  • You will need to check the raw request using the Browser Network tab to see how the posted data is being sent, if it's not being sent in the body of the request as key-value pairs it will be hard to pull it into the `Request` object without parsing the raw request using `Request.BinaryRead()`. – user692942 Mar 21 '18 at 07:44
  • 1
    @Lankymart I ran the code posted, and in the browser network tab ,the form data is shown as `{"firstname":"first","lastname":"second"}`. Looks like json to me. Doing a `Response.Write Request.form` shows the same thing. – Flakes Mar 21 '18 at 08:51

0 Answers0