简体   繁体   English

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

[英]jQuery or AngularJS Ajax “POST” request to server using code below however do not sending param data to server.

"POST" request to server using code below 使用以下代码向服务器发送“ POST”请求

however do not sending param data to server. 但是不要将参数数据发送到服务器。

I tried jQuery Way and 我尝试了jQuery Way

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. AngularJS方式。

    $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.
  });

but both are not sending "POST" query to server. 但两者都没有向服务器发送“ POST”查询。

what am i doing wrong 我究竟做错了什么

please help. 请帮忙。

server information 服务器信息

Mircrosoft/IIS8.0, ASP

Without seeing your server-side code it is difficult to say if that is a problem. 如果没有看到您的服务器端代码,很难说这是否是一个问题。 The JS you have presented generally looks okay. 您提交的JS通常看起来还不错。 You say that it runs without errors but fails to produce the expected results on the server. 您说它运行没有错误,但是无法在服务器上产生预期的结果。 So I suggest you add the server-side code. 因此,我建议您添加服务器端代码。

Both cases accept data as an object rather that a string which is generally more convenient. 两种情况都接受data作为对象,而不是通常更方便的字符串。 (avoids having to deal with encoding characters yourself) (避免自己处理字符编码)

For example: 例如:

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

Have a read of the the documentation for $.ajax and $http 阅读$ .ajax$ http的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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