jQuery或AngularJS Ajax“POST”请求使用下面的代码向服务器发送,但不向服务器发送参数数据

jQuery or AngularJS Ajax "POST" request to server using code below however do not sending param data to server.

本文关键字:服务器 代码 数据 参数 Ajax AngularJS POST 请求 jQuery      更新时间:2023-09-26

>使用以下代码向服务器发出"POST"请求

但是,不要将参数数据发送到服务器。

我尝试了jQuery方式和

var request = $.ajax({
  url: baseUrl,
  type:'post',
  data: 'userId=userabcd&passwd=abcd1234',
});
request.done(function( msg ) {
  console.log(msg);
});
request.fail(function( jqXHR, textStatus ) {
  alert( "Request failed: " + textStatus );
});

AngularJS Way.

    $http({
        method  : 'POST',
        url     : baseUrl,
        headers : { 'Content-Type': 'application/x-www-form-urlencoded' },  
        data    : 'userId=userabcd&passwd=abcd1234'
    }).success(function(data, status, headers, config) {
    console.log(data);
    console.log(status);
    console.log(headers);
    console.log(config);
    }).error(function(data, status, headers, config) {
            console.log(data);
    // called asynchronously if an error occurs
    // or server returns response with an error status.
  });

但两者都没有向服务器发送"POST"查询。

我做错了什么

请帮忙。

服务器信息

Mircrosoft/IIS8.0, ASP

如果没有看到你的服务器端代码,很难说这是否是一个问题。您呈现的 JS 通常看起来不错。您说它运行没有错误,但无法在服务器上产生预期的结果。所以我建议你添加服务器端代码。

这两种情况都接受data作为对象,而不是通常更方便的字符串。(避免自己处理编码字符)

例如:

data: {userId:'userabcd', passwd:'abcd1234'},

阅读 $.ajax 的文档并$http