Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用jquery进行AJAX post调用?_C#_Javascript_Jquery_Asp.net_Ajax - Fatal编程技术网

C# 使用jquery进行AJAX post调用?

C# 使用jquery进行AJAX post调用?,c#,javascript,jquery,asp.net,ajax,C#,Javascript,Jquery,Asp.net,Ajax,我找不到任何明确的例子来说明我想要什么。我想访问sample.aspx,并想通过POST(不是查询字符串)向其发送一些纯文本参数。如果成功了,我想看看JSON中的响应。如果失败了,我想做些事情来处理它。所以我需要成功和失败函数 如何执行此操作?通过POST的纯文本参数(不是查询字符串)。。请详细说明 var data = ; //POST PARAMS for send $.ajax({ url: '/sample.aspx', type: 'POST', conte

我找不到任何明确的例子来说明我想要什么。我想访问sample.aspx,并想通过
POST
(不是查询字符串)向其发送一些纯文本参数。如果成功了,我想看看JSON中的响应。如果失败了,我想做些事情来处理它。所以我需要成功和失败函数


如何执行此操作?

通过POST的纯文本参数(不是查询字符串)。。请详细说明

var data = ; //POST PARAMS for send 

$.ajax({
    url: '/sample.aspx',
    type: 'POST',
    contentType: "application/json",
    timeout: 10000,
    dataType: "html",
    data: data,
    success: function (response) {

    },
    error: function (error) {

    }
});
让我来为你解释一下

现在ajax是如何工作的

1-您发送请求(GET/POST)

注意:访问网页是get请求

2-页面输出响应

3-jquery读取页面。。它读取页面的html。。 因此,如果我使用$.ajax查看堆栈溢出,我将获得完整的html首页

这里有一个例子

$.ajax({
  url: "http://stackoverflow.com",
  type: "GET",
  data: {id : 'myid'}, // the url will become http://stackoverflow.com?id=myid
  dataType: "html", // what type of response your expecting 
  success : function(e){ // e is the response 
              console.log(e); // the will log the html of stackoverflow
             }
});
但是如果您希望得到的数据是json 然后,您在服务器端所要做的就是将页面输出(显示)为您想要的json字符串,jquery将读取它,您可以将其解析为json

下面是一个小的php示例

<?php
echo 'hi ' . $_GET['id'] ;
?>

你看过这里的例子了吗?:和/或这里?:关于这些例子有什么具体的不清楚之处?我们很乐意为您提供帮助,但您遇到的困难并不明显。数据部分和成功与否尚不清楚。如何获取数据,以及如何提交post参数?
data
可以像JSON对象中的一些键/值对一样简单。该页的“示例”部分有几个示例。这些键/值对是POST值。当AJAX调用成功时,
success
函数被调用,并从服务器传递响应。。。好的,谢谢大卫:)
'hi myid'