以下是一个请求的头信息实例
Accept: text/javascript , text/html, application/xml, text/xml, */* Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: close X-Requested-With: XMLHttpRequest X-Prototype-Version: 1.5.0_rc0 Content-Type: application/x-www-form-urlencoded
其中最重要的是 XMLHttpRequest 信息
那么用curl工具来模拟一个Ajax请求就很简单了
curl -H "X-Requested-With: XMLHttpRequest" http://ryan.heroku.com/store/add_to_cart/2
那么返回的数据将是一个Javascript代码
try { $$("div#notice").each(function(value, index) { value.hide(); }); Element.update("cart", "<div class='cart-title'>Your Shopping Cart</div>\n<table>\n <tr id='current_item'>\n <td>1 ×</td>\n <td>\u4e0a\u6d77\u9c9c\u82b1</td>\n <td class='item-price'>¥129.00</td>\n </tr>\n <tr class='total-line'>\n <td colspan='2'>Total</td>\n <td class='total-cell'>¥129.00</td>\n </tr>\n</table>\n<form method=\"post\" action=\"/store/checkout\" class=\"button-to\"><div><input type=\"submit\" value=\"Checkout\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"78brTTCuEhmyuLasMW/Q0GtgyzwGpfl4Fr8k1WLQFNU=\" /></div></form>\n<form method=\"post\" action=\"/store/empty_cart\" class=\"button-to\"><div><input type=\"submit\" value=\"Empty cart\" /><input name=\"authenticity_token\" type=\"hidden\" value=\"78brTTCuEhmyuLasMW/Q0GtgyzwGpfl4Fr8k1WLQFNU=\" /></div></form>\n"); $("cart").visualEffect("blind_down"); $("current_item").visualEffect("highlight", {"startcolor":"#88ff88","endcolor":"#114411"}); } catch (e) { alert('RJS error:\n\n' + e.toString()); alert('$$(\"div#notice\").each(function(value, index) {\nvalue.hide();\n});\nElement.update(\"cart\", \"<div class=\'cart-title\'>Your Shopping Cart</div>\\n<table>\\n <tr id=\'current_item\'>\\n <td>1 ×</td>\\n <td>\\u4e0a\\u6d77\\u9c9c\\u82b1</td>\\n <td class=\'item-price\'>¥129.00</td>\\n </tr>\\n <tr class=\'total-line\'>\\n <td colspan=\'2\'>Total</td>\\n <td class=\'total-cell\'>¥129.00</td>\\n </tr>\\n</table>\\n<form method=\\\"post\\\" action=\\\"/store/checkout\\\" class=\\\"button-to\\\"><div><input type=\\\"submit\\\" value=\\\"Checkout\\\" /><input name=\\\"authenticity_token\\\" type=\\\"hidden\\\" value=\\\"78brTTCuEhmyuLasMW/Q0GtgyzwGpfl4Fr8k1WLQFNU=\\\" /></div></form>\\n<form method=\\\"post\\\" action=\\\"/store/empty_cart\\\" class=\\\"button-to\\\"><div><input type=\\\"submit\\\" value=\\\"Empty cart\\\" /><input name=\\\"authenticity_token\\\" type=\\\"hidden\\\" value=\\\"78brTTCuEhmyuLasMW/Q0GtgyzwGpfl4Fr8k1WLQFNU=\\\" /></div></form>\\n\");\n$(\"cart\").visualEffect(\"blind_down\");\n$(\"current_item\").visualEffect(\"highlight\", {\"startcolor\":\"#88ff88\",\"endcolor\":\"#114411\"});'); throw e }
没有评论:
发表评论