Skip to content

Instantly share code, notes, and snippets.

function defaultAjaxErrorHandler(result, isAjaxError) {
// do stuff, hide spinner etc...
var defaultAjaxError = "Your friendly error message";
var errorToken = "Error:";
if(!isUndefinedOrNull(result) && !isUndefinedOrNull(result.responseText)) {
if(result.responseText.startsWith(errorToken)) {
// localhost
var x = (result.responseText.length > 350) ? 350 : result.responseText.length;
alert(result.responseText.substring(0, x) + "...\n\n - Check firebug console for more info.\n - This message for localhost only.");
@house9
house9 / gist:172347
Created August 21, 2009 19:26
jquery ajax post
$j.ajax({
type: "POST",
url: "/some_controller/some_action",
data: {
first_name: $j("#first_name").val(),
last_name: $j("#last_name").val(),
},
success: function(data, textStatus) {
// do what you like
},
<a href="http://www.google.com/" target="_blank">Google</a>
<a href="http://www.google.com/" class="target-blank">Google</a>
<script type="text/javascript">
$j(document).ready(function() {
$j('a.target-blank').click(function() {
this.target = '_blank';
});
}
</script>
require 'net/http'
require 'uri'
def get_html_content(requested_url)
url = URI.parse(requested_url)
full_path = (url.query.blank?) ? url.path : "#{url.path}?#{url.query}"
the_request = Net::HTTP::Get.new(full_path)
the_response = Net::HTTP.start(url.host, url.port) { |http|
http.request(the_request)
# remove all script tags
html_content = html_content.gsub(/<script.*?>[\s\S]*<\/script>/i, "")
.pagination { padding: 3px; margin: 3px; }
.pagination a { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #aaaadd; text-decoration: none; color: #000099; }
.pagination a:hover,
.pagination a:active { border: 1px solid #000099; color: #000; }
.pagination span.current { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #000099; font-weight: bold; background-color: #000099; color: #FFF; }
.pagination span.disabled { padding: 2px 5px 2px 5px; margin: 2px; border: 1px solid #eee; color: #ddd; }
/* From http://workingwithrails.com/railsplugin/4765-will-paginate */
# see http://gist.github.com/341290 (sort_index_controller_usage.rb)
# see http://gist.github.com/341295 (sort_index_view_usage.html.erb)
# The classes in this module help to enable sorting on index pages
# building sql order clauses and rendering html table header links
module SortIndex
SORT_KEY_ASC = 'asc'
SORT_KEY_DESC = 'desc'
SORT_DIRECTION_MAP = {
# see http://gist.github.com/341278 (sort_index.rb)
# see http://gist.github.com/341295 (sort_index_view_usage.html.erb)
# this example is an employees controller and using the will_paginate plugin
# however code should work fine with a standard ActiveRecord#find(:all, :order => ...
# put the sort_index.rb code in your rails lib directory
class EmployeesController < ApplicationController
# index sort constant config for sorting index action
# default is order by updated_at DESC
<%-
# see http://gist.github.com/341278 (sort_index.rb)
# see http://gist.github.com/341290 (sort_index_controller_usage.rb)
-%>
<table style="width:100%">
<thead>
<tr>
<%= @sortable.header_link('full_name', 'Name') %>
<%= @sortable.header_link('email', 'Email') %>
<%= @sortable.header_link('updated_at', 'Updated at') %>