Last active
January 2, 2016 21:39
-
-
Save deguchi/8364730 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.extend({ | |
| xpost: function(options) { | |
| var data, flush, form, iframe, key, name, url, val; | |
| name = "dummyxpostframe"; | |
| url = options.url; | |
| data = options.data; | |
| flush = function() { | |
| $("form[target=" + name + "]").remove(); | |
| return $("iframe[name=" + name + "]").remove(); | |
| }; | |
| iframe = $("<iframe></iframe>").attr("name", name).hide().appendTo("body"); | |
| if (typeof options.callback === "function") { | |
| iframe.load(options.callback); | |
| } | |
| form = $("<form method=\"POST\" />").attr("action", url).attr("target", name); | |
| for (key in data) { | |
| val = data[key]; | |
| if (key === 'urls') { | |
| form.append("<textarea name=\"" + key + "\">" + (val.join('\n')) + "</textarea>"); | |
| } else { | |
| form.append("<input type=\"hidden\" name=\"" + key + "\" value=\"" + val + "\">"); | |
| } | |
| } | |
| return form.hide().appendTo("body").submit(); | |
| } | |
| }); | |
| //使い方 | |
| param = { | |
| 'keyname': 'hogehoge', | |
| 'expire': 60 * 60 * 24, | |
| 'title': title, | |
| 'description': description, | |
| 'urls': urls | |
| }; | |
| url = "http://exapmle.com/post"; | |
| $.xpost({ | |
| url: url, | |
| data: param, | |
| callback: function() { | |
| return console.log('success'); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment