关于如何处理 javascript 小部件的想法? [英] Ideas on how to handle a javascript widget?

查看:21
本文介绍了关于如何处理 javascript 小部件的想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的朋友有一个搜索引擎,他想要一个可以放在其他网页上的小部件访问权限.如果我向搜索引擎发送请求,它会返回一个 XML 文件.请求看起来像这样:http://www.site.com/page.php?keyword=this+is+a+sample&page=1&num_days=3&source_id=site2.com&source_name=site2&source_url=sampleurl.php

My friend has a search engine that he wants to have a widget access that can be put on other web pages. If I send a request to the search engine, it returns an XML file. The request would look something like this: http://www.site.com/page.php?keyword=this+is+a+sample&page=1&num_days=3&source_id=site2.com&source_name=site2&source_url=sampleurl.php

我了解如何使用 Javascript 访问它.但是,我知道您不能进行跨域请求.我必须让它在搜索引擎的站点上加载一个新页面,而不是在它们所在站点的窗口中加载......对吗?任何想法或见解都非常感谢.

I understand how to access this by using Javascript. However, I know that you can't do a cross-domain request. I would have to have it load a new page at the search engines's site and not in the window at the the site they were located at....right? Any ideas or insight are greatly appreciated.

推荐答案

这里也有很好的解释:

什么是 JSONP?

jsonpString

覆盖回调函数名一个 jsonp 请求.这个值将是代替 callbackcallback=? 查询字符串的一部分在网址中.所以 {jsonp:'onJsonPLoad'}会导致 'onJsonPLoad=?'通过到服务器.

Override the callback function name in a jsonp request. This value will be used instead of callback in the callback=? part of the query string in the url. So {jsonp:'onJsonPLoad'} would result in 'onJsonPLoad=?' passed to the server.

 

jsonpCallbackString

指定回调函数名一个 jsonp 请求.这个值将是使用而不是随机名称由 jQuery 自动生成.它最好让 jQuery 生成一个唯一的名称,因为它会更容易管理请求并提供回调和错误处理.你可以想要指定回调时想要启用更好的浏览器缓存GET 请求.

Specify the callback function name for a jsonp request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests.

取自:http://api.jquery.com/jQuery.ajax/

这篇关于关于如何处理 javascript 小部件的想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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