来自小书签Ajax调用 [英] Ajax call from Bookmarklet

查看:114
本文介绍了来自小书签Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个书签的是,当点击,便会要求用户(在这种情况下,URL和一对夫妇等领域)的一些信息,然后将数据发送到PHP页面我的服务器上,然后显示的结果。

I am trying to create a bookmarklet that, upon clicking, would request some information from the user (a url and a couple other fields in this case) and then send that data to a php page on my server and then display the result.

我希望做一个Ajax调用这个让我实际上并不重定向到新的页面,刚拿到数据,但我想我会碰到阿贾克斯的同源策略限制....有基本上做同样的事情任何已知的方式?

I would like to do an Ajax call for this so that I don't actually redirect to the new page, just get the data but I assume I would run into the "Same Origin Policy" limitation of Ajax.... is there any known way of basically doing the same thing?

此外,什么是传递参数的最佳方法是什么?我已经有到位才能收到的参数,从形式的岗位信息的机制......有什么办法,我可以只重用呢?

Also, what would be the best way to pass the parameters? I already have a mechanism in place to recieve the parameters as a post message from a form...is there any way I could just reuse this?

推荐答案

您可以设置书签通过创建书签,并添加一张code以下的位置,但根据的同源策略的限制,只会工作在当前选项卡上的相同位置,这里的 www.google.com

You can set a bookmarklet by create a bookmark and add that piece of code below in location, but, according to same origin policy limitation, that will only work when the current tab is on the same location, here www.google.com.

如果我已经很好地理解您的需求,应该确定您的问题。

If I've understand well your needs, that should be ok for your problem.

var request = new XMLHttpRequest();
request.open("GET", "http://www.google.com", true);
request.onreadystatechange = function() {
  var done = 4, ok = 200;
  if (request.readyState == done && request.status == ok) {
    if (request.responseText) {
      alert(request.responseText);
    }
  }
};
request.send(null);

我不知道,如果POST会工作。

I don't know if POST would work.

这篇关于来自小书签Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆