最好的技术,让我的网站的消费者把动态数据纳入他们的网站

时间:2022-02-12 22:16:41

What I am asking, is what is the best way (i.e. the way that is easiest for neophyte web developers) to consume/integrate data that I make available on my website, into their own website.

我想问的是,什么是最好的方式(即对新手网站开发人员来说最简单的方式)来使用/集成我在我的网站上提供的数据到他们自己的网站上。

I have a website written in asp.net/sql server back end.

我有一个用asp.net/sql server后端写的网站。

I have clients that would like to be able to incorporate selections of data (say for example a table of data and some images that varies in length and is different for each user) into their website, so that the data looks like it belongs to them, and is branded by them (ideally the data would come to them with default css formatting, but they could customizing as much as they want). When the data on my website changes, the data on their website needs to change.

我有客户,希望能够把选择的数据(例如一个表的数据和一些图片为每个用户不同长度和不同)到他们的网站,以便数据看起来属于他们,由他们品牌(理想情况下,数据会用默认css格式化,但他们可以定制他们想要)。当我网站上的数据改变时,他们网站上的数据需要改变。

I'd like the user of my data to come to my website, login, and then be able to " copy" a customized script/code from my website, paste it into theirs and then just have it work, no matter what their website is written in (i.e. pure html, php, asp.net or others).

我想我的用户数据来我的网站,登录,然后可以“复制”一个定制的脚本/从我的网站代码,粘贴到他们,然后让它工作,无论他们的网站是什么写的(即纯html,php,asp.net或其他)。

I am assuming that a some sort of javascript script would be the best way to go, but I am at a loss as to how to make this completely simple for the user and what the script might contain (javascript is not my strong point yet). I.e. can I get a javascript on a clients website call a asp.net script on my server and then stream HTML back to their website..

我假设某种javascript脚本是最好的方法,但是我不知道如何为用户和脚本中可能包含的内容提供完全的简单性(javascript还不是我的强项)。例如,我能否在客户网站上获得一个javascript调用服务器上的asp.net脚本,然后将HTML流回他们的网站。

I am sure there must be examples of this done elsewhere, can someone point me in the right direction?

我相信肯定有其他地方也有这样的例子,有人能给我指出正确的方向吗?

EDIT: Let me try to give a better example of what I am trying to do.

编辑:让我试着给出一个更好的例子来说明我正在尝试做什么。

My app is not a real-estate app, but lets assume it us (pretend realtor.com the MLS database). Now every realtor in the country has their own website, and they are written in all kinds of languages so I can't assume anything about the consumer of the data, nor can I assume they have any programming expertise.

我的应用程序不是一个房地产应用程序,而是假设它是我们(假装realtor.com是MLS数据库)。现在这个国家的每个房地产经纪人都有自己的网站,他们用各种语言写,所以我不能对数据的消费者做出任何假设,我也不能假设他们有任何编程方面的专业知识。

If I was realtor.com owner, I'd like every realtor to be able to come to my website, copy a snippet of code (like I said, perhaps some javascript but I am not sure), go back to their website and paste it into the source of their page and then when one of their users goes to "Joesrealty.com" and clicks on "Show all properties for sale" the script/code/page would actually pull html down from my site by executing something on my website (realtor.com) and retrieve a list of all properties that that agent had for sale (say a table with accompanying picture).

如果我是realtor.com的所有者,我希望每个房地产经纪人都能访问我的网站,复制一段代码(就像我说的,可能是一些javascript,但我不确定),回到他们的网站并粘贴到页面的源代码,然后当他们的一个用户去“Joesrealty.com”,单击“显示所有属性出售”脚本/代码/页面会从我的网站通过执行一些html下拉在我的网站上(realtor.com)和检索所有的属性的列表,代理销售(例如一个表伴随图)。

I know I saw a great implementation of this somewhere on a big name site, but for the life of me can't remember where I saw it, and never bothered at the time to try and see what technology they used.

我知道我在一个知名网站的某个地方看到了一个很棒的实现,但是我的一生都记不起我在哪里见过它,而且我也从来没有费心去尝试看看他们使用了什么技术。

5 个解决方案

#1


5  

I have clients that would like to be able to incorporate selections of data (...) into their website, so that the data looks like it belongs to them, and is branded by them

我的客户希望能够将数据(…)的选择合并到他们的网站中,这样数据看起来就像是属于他们的,并且被他们打上了标签。

A number of sites make this functionality available via snippets of javascript code, e.g. TechnicalJobs.ie.

许多站点通过javascript代码片段(例如技术工作)使此功能可用。

The user pastes some javascript code in to their page. This code calls back to your website to pull the most recent data, then displays it on the client's website.

用户将一些javascript代码粘贴到他们的页面中。此代码返回到您的网站,提取最新的数据,然后显示在客户的网站上。

Example

例子

We can send back an unstyled list of new widgets, and allow the user to style the css to tweak the display on their site.

我们可以返回一个未样式化的新窗口小部件列表,并允许用户对css进行样式化,以调整其站点上的显示。

On your page, tell the user to copy the following javascript in to their page:

在您的页面上,告诉用户将以下javascript复制到他们的页面:

<script src="http://www.yoursite.com/widgets.asp?action=getNewWidgets"
   type="text/javascript"></script>

<script type="text/javascript">
   showWidgets('widget-container', 'widget-list');
</script>

On your site, widgets.asp will be responsible for looking up the data on new widgets from your database. It will pull the data together, then output it in JSON-encoded format. The logic is all handled in ASP or your language of choice, and outputted in the format outlined below. This page will also return the showWidgets method, which handles converting your data for display on the user's website.

在你的网站上,小部件。asp将负责从数据库中查找新窗口小部件的数据。它将把数据拉到一起,然后以json编码的格式输出数据。逻辑都是用ASP或您的选择语言处理的,并且输出的格式如下所示。此页面还将返回showWidgets方法,该方法处理将数据转换为用户网站上的显示。

widgets.asp's final output should look something like:

小部件。asp的最终输出应该如下所示:

// Widget product data 
var widgets = [
     {
       "url":"http:\/\/www.yoursite.com\/widgets\/foo-widget",
       "title":"Brand new Foo Widget, available now!"
     },
     {
       // More widget details..
     }
];

// Function to display list of widgets on calling page    
function showWidgets(container_div, style)
{
    // Start building the html for the list
    var html = "<ul class='" + style + "'>";

    // Loop through all of the widgets we have, ading to list
    for (i = 0; i < widgets.length; i++)
    {
        html += "<li><a target='_blank' href='" + widgets[i].url + "'>";
        html += widgets[i].title;
        html += "</a></li>";
    }
    html += "</ul>";

    // We have the html, now write to the container     
    // If the user hasn't created this already, we'll make it      
    if (document.getElementById(container_div))
    {
        document.getElementById(container_div).innerHTML = html;    
    }
    else
    {
        // Target div wasn't made by user, create it inline
        document.write("<div id='" + container_div + "'>");
        document.write(html);
        document.write("</div>");
    }
}

Once the user embeds your js code on to their page, the output of widgets.asp will take care of writing out the recent data. You can specify styles etc, or leave this all up to the end user to style it in accordance with the rest of their website.

一旦用户将您的js代码嵌入到他们的页面,窗口小部件的输出。asp将负责编写最近的数据。您可以指定样式等等,或者让最终用户根据他们网站的其他部分来设计样式。

#2


1  

Your list of requirements seem to be pretty broad.

您的需求列表似乎相当广泛。

I was going to suggest building some kind of RESTful Web Service, through which users could consume your data in what ever format is most appropriate. This could be XML or JSON if they have the capability to parse that, or if they just want to embed an iframe in their page it could return plain HTML.

我打算建议构建某种RESTful Web服务,通过它,用户可以以最合适的格式使用您的数据。这可以是XML或JSON,如果他们有能力解析它,或者如果他们只是想在他们的页面中嵌入iframe,它可以返回纯HTML。

Take a look at some of Yahoo's Web Services and get an idea of how they do things:

看看雅虎的一些网络服务,了解一下它们是如何运作的:

http://developer.yahoo.com/

http://developer.yahoo.com/

#3


1  

Any kind of web service requires programming on the consumer-side, so that's not an option for you. What you are trying to do is generally done with Javascript. Take a look at what Amazon offers for associate sites, Technorati, .... there are many other examples.

任何类型的web服务都需要客户端编程,所以这不是您的选择。您要做的通常是使用Javascript完成。看看亚马逊提供关联网站Technorati,....还有很多其他的例子。

The way it works - your client includes a javascript file from your site, which would then execute as part of the page rendering in the browser, and you can include your content into the resulting output stream. It is important to understand that you have to serve the script. Browsers prevent cross-site scripting because of potential security risks. For instance, in order to include Amazon's search widget, you only need to put the following code into your page (I removed the query string parameters for clarity):

它的工作方式——您的客户端包含来自站点的javascript文件,该文件将作为浏览器中的页面呈现的一部分执行,您可以将内容包含到结果输出流中。理解您必须为脚本服务是很重要的。由于潜在的安全风险,浏览器防止跨站点脚本编程。例如,为了包含Amazon的search小部件,您只需将以下代码放入您的页面(为了清晰起见,我删除了查询字符串参数):

<SCRIPT charset="utf-8" type="text/javascript" 
        src="http://ws.amazon.com/widgets/q?...">
</SCRIPT> 
<NOSCRIPT>
<A HREF="http://ws.amazon.com/widgets/q?...">
        Amazon.com Widgets</A>
</NOSCRIPT>

If a browser does not have Java script enabled, it only shows a link. You can wrap DIV tags around this to control the size of your widget. Your only other option is an <IFRAME>.

如果浏览器没有启用Java脚本,它只显示一个链接。您可以围绕它包装DIV标记来控制小部件的大小。您唯一的其他选项是

#4


0  

You could expose a web service that they could call. Creating a web service in asp.net is very simple to do.

您可以公开他们可以调用的web服务。在asp.net中创建web服务非常简单。

You can make methods for different data elements you want to expose, and the customer can call the service with any params you make available in the method for them to further filter the data as needed.

您可以为要公开的不同数据元素创建方法,客户可以使用方法中提供的任何参数调用服务,以便根据需要进一步过滤数据。

#5


0  

Create a URL that can generate response in different formats based on a parameter or content-accept-header; I'd recommend HTML, XML and JSON. HTML for clients that want to use a IFRAME or have a Javascript do a document.write, XML and JSON for clients that want to process the data before outputting it, either with client-side Javascript or serverside using whatever language they're using. You can create a Javascript for your clients to use that fetches the HTML and does a document.write as well as include some default css.

创建一个URL,该URL可以根据参数或内容接收头生成不同格式的响应;我推荐HTML、XML和JSON。对于希望使用IFRAME或使用Javascript编写文档的客户端,HTML。对于在输出数据之前希望处理数据的客户端,可以使用客户端Javascript或服务器端使用他们使用的任何语言编写、XML和JSON。您可以为您的客户端创建一个Javascript,用于获取HTML并执行文档。编写并包含一些默认的css。

#1


5  

I have clients that would like to be able to incorporate selections of data (...) into their website, so that the data looks like it belongs to them, and is branded by them

我的客户希望能够将数据(…)的选择合并到他们的网站中,这样数据看起来就像是属于他们的,并且被他们打上了标签。

A number of sites make this functionality available via snippets of javascript code, e.g. TechnicalJobs.ie.

许多站点通过javascript代码片段(例如技术工作)使此功能可用。

The user pastes some javascript code in to their page. This code calls back to your website to pull the most recent data, then displays it on the client's website.

用户将一些javascript代码粘贴到他们的页面中。此代码返回到您的网站,提取最新的数据,然后显示在客户的网站上。

Example

例子

We can send back an unstyled list of new widgets, and allow the user to style the css to tweak the display on their site.

我们可以返回一个未样式化的新窗口小部件列表,并允许用户对css进行样式化,以调整其站点上的显示。

On your page, tell the user to copy the following javascript in to their page:

在您的页面上,告诉用户将以下javascript复制到他们的页面:

<script src="http://www.yoursite.com/widgets.asp?action=getNewWidgets"
   type="text/javascript"></script>

<script type="text/javascript">
   showWidgets('widget-container', 'widget-list');
</script>

On your site, widgets.asp will be responsible for looking up the data on new widgets from your database. It will pull the data together, then output it in JSON-encoded format. The logic is all handled in ASP or your language of choice, and outputted in the format outlined below. This page will also return the showWidgets method, which handles converting your data for display on the user's website.

在你的网站上,小部件。asp将负责从数据库中查找新窗口小部件的数据。它将把数据拉到一起,然后以json编码的格式输出数据。逻辑都是用ASP或您的选择语言处理的,并且输出的格式如下所示。此页面还将返回showWidgets方法,该方法处理将数据转换为用户网站上的显示。

widgets.asp's final output should look something like:

小部件。asp的最终输出应该如下所示:

// Widget product data 
var widgets = [
     {
       "url":"http:\/\/www.yoursite.com\/widgets\/foo-widget",
       "title":"Brand new Foo Widget, available now!"
     },
     {
       // More widget details..
     }
];

// Function to display list of widgets on calling page    
function showWidgets(container_div, style)
{
    // Start building the html for the list
    var html = "<ul class='" + style + "'>";

    // Loop through all of the widgets we have, ading to list
    for (i = 0; i < widgets.length; i++)
    {
        html += "<li><a target='_blank' href='" + widgets[i].url + "'>";
        html += widgets[i].title;
        html += "</a></li>";
    }
    html += "</ul>";

    // We have the html, now write to the container     
    // If the user hasn't created this already, we'll make it      
    if (document.getElementById(container_div))
    {
        document.getElementById(container_div).innerHTML = html;    
    }
    else
    {
        // Target div wasn't made by user, create it inline
        document.write("<div id='" + container_div + "'>");
        document.write(html);
        document.write("</div>");
    }
}

Once the user embeds your js code on to their page, the output of widgets.asp will take care of writing out the recent data. You can specify styles etc, or leave this all up to the end user to style it in accordance with the rest of their website.

一旦用户将您的js代码嵌入到他们的页面,窗口小部件的输出。asp将负责编写最近的数据。您可以指定样式等等,或者让最终用户根据他们网站的其他部分来设计样式。

#2


1  

Your list of requirements seem to be pretty broad.

您的需求列表似乎相当广泛。

I was going to suggest building some kind of RESTful Web Service, through which users could consume your data in what ever format is most appropriate. This could be XML or JSON if they have the capability to parse that, or if they just want to embed an iframe in their page it could return plain HTML.

我打算建议构建某种RESTful Web服务,通过它,用户可以以最合适的格式使用您的数据。这可以是XML或JSON,如果他们有能力解析它,或者如果他们只是想在他们的页面中嵌入iframe,它可以返回纯HTML。

Take a look at some of Yahoo's Web Services and get an idea of how they do things:

看看雅虎的一些网络服务,了解一下它们是如何运作的:

http://developer.yahoo.com/

http://developer.yahoo.com/

#3


1  

Any kind of web service requires programming on the consumer-side, so that's not an option for you. What you are trying to do is generally done with Javascript. Take a look at what Amazon offers for associate sites, Technorati, .... there are many other examples.

任何类型的web服务都需要客户端编程,所以这不是您的选择。您要做的通常是使用Javascript完成。看看亚马逊提供关联网站Technorati,....还有很多其他的例子。

The way it works - your client includes a javascript file from your site, which would then execute as part of the page rendering in the browser, and you can include your content into the resulting output stream. It is important to understand that you have to serve the script. Browsers prevent cross-site scripting because of potential security risks. For instance, in order to include Amazon's search widget, you only need to put the following code into your page (I removed the query string parameters for clarity):

它的工作方式——您的客户端包含来自站点的javascript文件,该文件将作为浏览器中的页面呈现的一部分执行,您可以将内容包含到结果输出流中。理解您必须为脚本服务是很重要的。由于潜在的安全风险,浏览器防止跨站点脚本编程。例如,为了包含Amazon的search小部件,您只需将以下代码放入您的页面(为了清晰起见,我删除了查询字符串参数):

<SCRIPT charset="utf-8" type="text/javascript" 
        src="http://ws.amazon.com/widgets/q?...">
</SCRIPT> 
<NOSCRIPT>
<A HREF="http://ws.amazon.com/widgets/q?...">
        Amazon.com Widgets</A>
</NOSCRIPT>

If a browser does not have Java script enabled, it only shows a link. You can wrap DIV tags around this to control the size of your widget. Your only other option is an <IFRAME>.

如果浏览器没有启用Java脚本,它只显示一个链接。您可以围绕它包装DIV标记来控制小部件的大小。您唯一的其他选项是

#4


0  

You could expose a web service that they could call. Creating a web service in asp.net is very simple to do.

您可以公开他们可以调用的web服务。在asp.net中创建web服务非常简单。

You can make methods for different data elements you want to expose, and the customer can call the service with any params you make available in the method for them to further filter the data as needed.

您可以为要公开的不同数据元素创建方法,客户可以使用方法中提供的任何参数调用服务,以便根据需要进一步过滤数据。

#5


0  

Create a URL that can generate response in different formats based on a parameter or content-accept-header; I'd recommend HTML, XML and JSON. HTML for clients that want to use a IFRAME or have a Javascript do a document.write, XML and JSON for clients that want to process the data before outputting it, either with client-side Javascript or serverside using whatever language they're using. You can create a Javascript for your clients to use that fetches the HTML and does a document.write as well as include some default css.

创建一个URL,该URL可以根据参数或内容接收头生成不同格式的响应;我推荐HTML、XML和JSON。对于希望使用IFRAME或使用Javascript编写文档的客户端,HTML。对于在输出数据之前希望处理数据的客户端,可以使用客户端Javascript或服务器端使用他们使用的任何语言编写、XML和JSON。您可以为您的客户端创建一个Javascript,用于获取HTML并执行文档。编写并包含一些默认的css。