使用 jQuery(插件?)的非 ajax GET/POST

Non-ajax GET/POST using jQuery (plugin?)(使用 jQuery(插件?)的非 ajax GET/POST)
本文介绍了使用 jQuery(插件?)的非 ajax GET/POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

这是我觉得我错过了在 Google 上找到答案的关键关键字的情况之一......

This is one of those situations where I feel like I'm missing a crucial keyword to find the answer on Google...

我有一袋参数,我想让浏览器导航到带有参数的 GET URL.作为一个 jQuery 用户,我知道如果我想发出 ajax 请求,我会这样做:

I have a bag of parameters and I want to make the browser navigate to a GET URL with the parameters. Being a jQuery user, I know that if I wanted to make an ajax request, I would simply do:

$.getJSON(url, params, fn_handle_result);

但有时我不想使用 ajax.我只是想提交参数并返回一个页面.

But sometimes I don't want to use ajax. I just want to submit the parameters and get a page back.

现在,我知道我可以循环参数并手动构造一个 GET URL.对于 POST,我可以动态创建一个表单,用字段填充它并提交.但我确信有人已经编写了一个可以做到这一点的插件.或者也许我错过了一些东西,你可以用核心 jQuery 来做.

Now, I know I can loop the parameters and manually construct a GET URL. For POST, I can dynamically create a form, populate it with fields and submit. But I'm sure somebody has written a plugin that does this already. Or maybe I missed something and you can do it with core jQuery.

那么,有人知道这样的插件吗?

So, does anybody know of such a plugin?

基本上,我想要写的是:

Basically, what I want is to write:

$.goTo(url, params);

可选

$.goTo(url, params, "POST");

推荐答案

在我在 IE8 上试用之前,jQuery 插件似乎运行良好.我必须做些小改动才能让它在 IE 上运行:

jQuery Plugin seemed to work great until I tried it on IE8. I had to make this slight modification to get it to work on IE:

(function($) {
    $.extend({
        getGo: function(url, params) {
            document.location = url + '?' + $.param(params);
        },
        postGo: function(url, params) {
            var $form = $("<form>")
                .attr("method", "post")
                .attr("action", url);
            $.each(params, function(name, value) {
                $("<input type='hidden'>")
                    .attr("name", name)
                    .attr("value", value)
                    .appendTo($form);
            });
            $form.appendTo("body");
            $form.submit();
        }
    });
})(jQuery);

这篇关于使用 jQuery(插件?)的非 ajax GET/POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)