AJAX& web API参数传递 [英] AJAX & web API parameter passing

查看:67
本文介绍了AJAX& web API参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我们正在尝试对.net Web API进行ajax调用。

这是一个GET调用,我们传递了4个字符串参数。让我们说

Emp ID,加入日期,上次工作日期,部门名称。

Web API根据编写的逻辑进行一些后端处理。

当我们从visual studio本地运行代码时,调用工作正常。

但是当我们在IIS中部署代码并尝试进行调用时,执行会转到成功块,但是API没有得到AJAX发送的参数。

可能是什么原因?

Ajax html页面和API保留在同一目录中。所以没有CORS问题。

请建议。



请忽略

Hello Everyone,

We are trying to make an ajax call to a .net Web API.
It's a GET call and we are passing 4 string parameters. let's say
Emp ID, Joining Date, Last Working Date, Department Name.
The web API does some back end processing based on the logic written.
The calls works fine when we run the code from visual studio locally.
However when we deploy the code in IIS and try make the call, the execution goes to the success block, but API doesn't get the parameters sent by AJAX.
What could be the reason?
The Ajax html page and the API remain in the same directory. So no CORS issue.
Kindly suggest.

please ignore

$.ajax({
                type: "GET",
                url: "dadasdasad",
                contentType: "application/json; charset=utf-8",
                dataType: "jsonp",
                success: function (data) {
                    console.log(data);
                    weHaveSuccess = true;
                    alert('success');
                }





代码可以与之一起使用。



谢谢



我尝试过:





the code works with or with out it.

thanks

What I have tried:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
    var cn = "2.10 - App Account Provisioning";
    var aid = "1363633";
    var sd = "4/19/2019";
    var ed = "5/15/2019";
    $(document).ready(function () {
        $("#btnGetdata").click(function () {
            var weHaveSuccess = false;
            $.ajax({
                type: "GET",
                url: "dadasdasad",
                contentType: "application/json; charset=utf-8",
                dataType: "jsonp",
                success: function (data) {
                    console.log(data);
                    weHaveSuccess = true;
                    alert('success');
                },
                complete: function () {
                    if (!weHaveSuccess) {
                        $.ajax({
                            type: "GET",
                            url: "https://grc-stg-web1.vmware.com:9443/api/values/GET",
                            cache: false,
                            data: { ctrlsname: cn, asstid: aid, auditstdate: sd, auditenddate: ed },
                            contentType: "application/json; charset=utf-8",
                            dataType: "jsonp",
                            success: function (data) {
                                console.log(data);
                                alert('success in website.');
                            },
                            error: function () {
                                console.log('Error');
                                alert('Failed');
                            }
                        })
                    }
                }
            })
        });
    });
</script>
</head>
<body>
<div>
<input type="button" id="btnGetdata" value="InsertData" />
    </div>
</body>
</html>

推荐答案

.ajax({
类型:GET,
url:dadasdasad,
c ontentType:application / json; charset = utf-8,
dataType:jsonp,
成功:函数(数据){
console.log(data);
weHaveSuccess = true;
警告('成功');
}
.ajax({ type: "GET", url: "dadasdasad", contentType: "application/json; charset=utf-8", dataType: "jsonp", success: function (data) { console.log(data); weHaveSuccess = true; alert('success'); }





代码可以与之一起使用。



谢谢



我的尝试:





the code works with or with out it.

thanks

What I have tried:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
    var cn = "2.10 - App Account Provisioning";
    var aid = "1363633";
    var sd = "4/19/2019";
    var ed = "5/15/2019";


(document).ready(function() {
(document).ready(function () {


(#btnGetdata)。click(function(){
var weHaveSuccess = false;
("#btnGetdata").click(function () { var weHaveSuccess = false;


这篇关于AJAX&amp; web API参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆