我本周遇到的一种情况:我们有一个jQuery Ajax调用,它返回服务器以获取数据
$.ajax(
{
type: "POST",
contentType: "application/json; charset=utf-8",
url: fullMethodPath,
data: data,
dataType: "json",
success: function(response) {
successCallback(response);
},
error: errorCallback,
complete: completeCallback
});
Run Code Online (Sandbox Code Playgroud)
fullMethodPath是指页面上静态方法的链接(比方说/MyPage.aspx/MyMethod).
public partial class MyPage : Page
{
// snip
[WebMethod]
public static AjaxData MyMethod(string param1, int param2)
{
// return some data here
}
}
Run Code Online (Sandbox Code Playgroud)
这个工作,没问题.
一位同事试图用类型为"GET"的那个替换这个电话.它坏了,我不得不解决它.最后,我回到POST,因为我们需要快速修复,但它一直在困扰我,因为在这种情况下,语义上GET更"正确".
据我所知,jQuery将数据中的对象转换为查询字符串:/MyPage.aspx/MyMethod?param1=value1¶m2=value2但我可以得到的只是页面的内容MyPage.aspx.
这只是Page方法的"功能",还是有办法使GET请求有效?
如果if (n > 0)它返回正常结果,但if (n >= 0)它返回正常结果+ 1,我不明白,因为0*0 = 0.如果有人知道为什么这样做我想知道这个.
import java.util.*;
// Recursive method returns sum of first n squares
public class RecursiveSum
{
public static void main(String[] args)
{
while (true)
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter a number:\tIf you want to exit, enter a negative number.");
int n = keyboard.nextInt();
if (n < 0)
System.exit(0);
System.out.println("sum(" + n + ") = " + sum(n));
}
}
public static int sum(int n)
{
int …Run Code Online (Sandbox Code Playgroud)