express ajax jsonp,javascript - Node.js(express) .end() with JSONP - Stack Overflow

2023-11-06

As user2840784 points out, you need the callback for this to work. To elaborate on their answer, the client library will need to specify a 'client side callback' when making the request for example:

http://my-service.com/get-data.json?callback=callThisFunction

If you're using jQuery on the client side, jQuery will provide the callback name for you when you make the $.ajax request, so your request will look like:

http://my-service.com/get-data.json?callback=jQuery123456789

Behind the scenes, jQuery secretly creates a function with the name jQuery123456789 (or something) to handle your data when it's loadded.

What you have to do is make sure you wrap your JSON output with the callback function name, so if your response JSON would look like this:

{"a":1, "b":2}

... then you need to wrap it so it looks like this:

jQuery123456789('{"a":1, "b":2}')

Again, as user2840784 pointed out, you can get the name of the callback from req.query.jsonp.

Hth,

Aaron

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

express ajax jsonp,javascript - Node.js(express) .end() with JSONP - Stack Overflow 的相关文章

随机推荐

  • echarts地图自定义tooltip样式

    效果图 自定义tooltip样式 tooltip position 50 50 trigger item backgroundColor rgba 0 0 0 0 borderColor rgba 0 0 0 0 extraCssText
  • SQL学习笔记——REGEXP运算符

    REGEXP运算符 是正则表达式 regular expression 的缩写 正则表达式在搜索字符串时非常强大 下面是关于它的应用 1 查找名字中包含field的顾客 select from customers where last na
  • pytorch从0开始安装

    文章目录 一 安装anaconda 1 安装pytorch前需要先安装anaonda 首先进入官网 Anaconda The World s Most Popular Data Science Platform 进行安装相应的版本 2 接着
  • java编辑文件FileUtils

    FileUtiles 进行获取文件 把每行添加到字符串数组里 然后对每行进行替换 最后写回文件里 import org apache commons io FileUtils try str FileUtils readFileToStri
  • Python 学习资源 ( 整理日期2010-02-24 )

    Python 简明教程 入门必看 在线 浏览 http www woodpecker org cn 9081 doc abyteofpython cn chinese index html PDF http bbs chinaunix ne
  • 小酌Django4——博客文章展示

    小酌Django4 博客文章展示 文章列表页 已发布的文章列表展示页面 展示文章标题 交互模式下的数据读取 blog models py中创建数据模型后 Django会自动提供数据库抽象的API ORM 进行增删改查操作 使用命令pytho
  • TCP/IP 通信

    学习资料来源 正点原子STM32 目录 TCP IP TCP连接 TCP终止连接 MAC LAN8720 DMA LWIP内存分配 内存池 内存堆 数据包管理 pbuf介绍 数据包申请与释放 网络接口管理 ARP协议 TCP IP TCP是
  • input 去除边框/设置placeholder样式--SCSS

    input 去除边框 设置placeholder样式 SCSS el input edit v deep input webkit input placeholder font size 22px el input inner border
  • scrapy爬虫框架实例二 当当图书信息

    spider py import scrapy from DD items import DdItem class DdSpider scrapy Spider name dd allowed domains http search dan
  • 如何用crontab每隔1分钟执行一个命令行脚本

    我在 home 下面写了一个a sh bin sh echo hello gt home hello txt 然后在crontab e中设置了 1 home a sh 为何等了好几分钟 home下面还是没有hello txt呢 指定一下用什
  • python制造童年回忆【猫和老鼠小游戏】(附源码+详细分析)

    周末好吖 铁汁们 到了看动画片 打游戏 敲代码 的美好宅时光了 大家小时候有没有看过一部 猫和老鼠 的动画片80 90 00 应该都知道吧 10后可能就没听过了 接下来 让我隆重介绍本期游戏的主角们 他们就是 汤姆和杰瑞 相信不用我多介绍吧
  • window11系统基于 wsl2 安装Linux发行版ubuntu,并安装docker及vscode

    前景介绍 WSL是 Windows Subsystem for Linux 的缩写 顾名思义 WSL就是Windows系统的Linux子系统 其作为Windows组件搭载在Windows10周年更新 1607 后的Windows系统中 既然
  • 字符串和数学方法

    字符串 用单引号或双引号包起来 字符串也像数组一样 有数字索引 可以通过响应的索引可以通过响应索引对应字符 获取字符串的长度str length 获取第一个字符 0 获取最后一个字符 str str length 1 字符串常用方法 1 c
  • Ext.grid.GridPanel 单双行颜色样式(斑马线)

    Ext grid GridPanel stripeRows 斑马线 BUG 解决方案 在Ext Version2 2 和目前的Version3 1 1 Version3 2 里面存在一个BUG 就是当设置了 stripeRows true
  • C++类模板

    C 类模板 第二节 类模板 变量模板 别名模板 类模板的基本范例和模板参数的推断 类模板 是产生类的模具 通过给定的模板参数 生成具体的类 也就是实例化一个特定的类 比如 vector 引入类模板的目的 减少代码冗余 基本范例 namesp
  • 详解Java数组的四种拷贝方式

    java 数组一共有四种拷贝方式 for循环 copyof copyOfRange arraycopy clone 本文为大家介绍这四种 深拷贝与浅拷贝的区别 假设现在有原数组A以及拷贝后的数组B 若是改变A中的某一个值 B数组随之相应的发
  • iPhone 界面尺寸以及各种图表尺寸

    iPhone界面尺寸 设备 屏幕尺寸 开发尺寸 状态栏高度 导航栏高度 tab栏 高度 高宽比 iPhone 4 4S 3 5英寸 320 480 40px 88px 98px 0 66 iPhone 5 5S 5C SE 4英寸 320
  • 你真的不能再穷下去了:下班后用Python做兼职赚钱,在家就能做副业

    北京赚钱北京花 成为了北漂间心照不宣又闭口不言的默契 2021年 如果你只想凭借死工资就拥有好生活的话 很可能是痴人说梦 不要杠 让我来给你算笔账 拿一线城市普通的运营专员来举例 月薪8000 10000元是常态 那每个月的日常支出是多少呢
  • Vue中报错Error in v-on handler: “TypeError: dateObject.getTime is not a function“

    发现在vue项目里修改更新数据功能 提交更改后的表单数据报错 TypeError dateObject getTime is not a function 时间数据有问题 找到原因是rules中type date 造成的 因为初始化成了st
  • express ajax jsonp,javascript - Node.js(express) .end() with JSONP - Stack Overflow

    As user2840784 points out you need the callback for this to work To elaborate on their answer the client library will ne