如何使用没有ajax的params发送get请求

mar*_*cks 5 jquery

我想发送一个普通的get请求,它像普通的get请求一样替换整个页面但是如果可能的话使用jQuery.我还需要在请求中发送2个参数.

我不想用结果替换我的文档中的一些内容,结果是完整的文档.

这里的代码仍然发送​​了一个ajax请求,我的页面没有响应刷新.

$.get({
       url: '/swap_games', 
       data: { source: sourceElem, target: targetElem } 
});
Run Code Online (Sandbox Code Playgroud)

Gab*_*abe 3

jQuery 有一个load()方法可以为您完成此操作。

.load( url, [data,] [complete(responseText, textStatus, XMLHttpRequest)] )
Run Code Online (Sandbox Code Playgroud)

示例如下:

$('html').load('/swap_games', data: { source: sourceElem, target: targetElem } );
Run Code Online (Sandbox Code Playgroud)

或者使用回调:

$('html').load('/swap_games', data: { source: sourceElem, target: targetElem }, function() {
   alert('load complete callback');
});
Run Code Online (Sandbox Code Playgroud)

更多信息请点击此处