首页 > 其他分享 >原生js掉接口

原生js掉接口

时间:2023-06-02 11:11:32浏览次数:25  
标签:原生 const url 接口 js xhr JSON inputpath data

1.get请求

var inputpath = document.getElementById("inputpath").value;   //获取输入框的值作为参数

                        // 创建一个ajax对象
                        const xhr = new XMLHttpRequest();


                        xhr.open("get", urls + '?url=' + inputpath, );
                        xhr.onload = function() {
                            if (xhr.status === 200) {
                                const data = JSON.parse(xhr.responseText);
                                console.log(data);
                                if (data.code == 200) {
                                    // myvideo.style.display = "block";
                                    video = data.data.url
                                }else{
                                    // video=""
                                    // myvideo.style.display = "none";
                                }
                            } else {
                                console.error("请求失败");
                            }
                        };
                        // 发送请求
                        xhr.send();

2.post请求

 

    const xhr = new XMLHttpRequest();
        const url = 'http://example.com/api';
        const data = {
            name: 'John',
            age: 30
        };
        const params = JSON.stringify(data);
        xhr.open('POST', url, true);
        xhr.setRequestHeader('Content-type', 'application/json');
        xhr.onreadystatechange = function() {
            if (xhr.readyState === 4 && xhr.status === 200) {
                const response = JSON.parse(xhr.responseText);
                console.log(response);
            }
        };
        xhr.send(params);

 

标签:原生,const,url,接口,js,xhr,JSON,inputpath,data
From: https://www.cnblogs.com/bshit/p/17451210.html

相关文章

  • nodejs koa框架下载和导入excel
    ac.jsconstservice=require("../service/model.service");consturlencode=require("urlencode");consthelper=require("../../utils/helper");module.exports={/***@description:下载导入度量模板*@param{type}*@retur......
  • 本地安装node.js安装,使用npm下载插件
    操作系统:windows10开发工具:VS Code 1.下载node.js文件   全程下一步即可。 2.打开vscode运行终端(此处打开的额终端路径是你当前的项目根目录):  node中自带npm,所以安装号node就已经安装号npm了,使用npm-v课查看版本。 3.使用npm安装mock.js案例:命令:npminstall......
  • 面向切面编程和面向接口编程的区别
    面向切面编程:手段:分离业务的主逻辑和次逻辑的一种思想。目的:解决的是逻辑分离问题(主逻辑和次逻辑分开,其实主要是分离业务逻辑和非业务逻辑分开)。案例:我们开发项目的时候基本都要去连接数据库操作数据等,但是都会涉及到事务的提交,这时我们就用到了面向切面编程,我们在业务层只写自己......
  • vue系列---【vue 使用decimal.js 解决小数相加合计精确度丢失问题】
    使用npm安装decimal.js库npminstalldecimal.js2.在Vue组件中引入该库importDecimalfrom'decimal.js';3.使用示例footerMethod({columns,data}){letsumArr=[];columns.map((column,columnIndex)=>{if(columnIndex===0){su......
  • 根据Servie接口 生成 Controller 代码-因业务需要简单应付勿喷
    附上垃圾代码(勿喷,只不过为了应付工作需求,百十来个service都要创建对应的controller的需求,复制实在吃不消,说明一下就是简单的字符串替换操作)ApplicationControllerimportjava.io.BufferedReader;importjava.io.File;importjava.io.FileReader;importjava.io.IOExcepti......
  • Java 对象转 Json
    <!--json依赖--><dependency><groupId>com.fasterxml.jackson.core</groupId><artifactId>jackson-core</artifactId><version>2.11.2</version></dependency>......
  • P4036 [JSOI2008] 火星人
    暴力水过了wwwwwwwwwwwwwww#include<bits/stdc++.h>//================================================//#defineLOCALFLANDREKAWAII#ifndefLOCALconstexprintSIZE(1<<20);charin[SIZE],out[SIZE],*p1=in,*p2=in,*p3=out;#definegetchar(......
  • JS逆向实战16——猿人学第20题 新年挑战-wasm进阶
    声明本文章中所有内容仅供学习交流,抓包内容、敏感网址、数据接口均已做脱敏处理,严禁用于商业用途和非法用途,否则由此产生的一切后果均与作者无关,若有侵权,请联系我立即删除!网站https://match.yuanrenxue.cn/match/20网站分析首先进去网站,我们查看下接口发现有两个值是改变......
  • node.js安装
    F:\ProgramFiles\nodejs\ windows安装npm教程(nodejs)[就是参照这个编辑安装]https://www.cnblogs.com/kakashi-feng/p/16483727.htmlnpm安装详细教程https://blog.csdn.net/cleve_baby/article/details/125632341npmconfigsetcache"F:\ProgramFiles\nodejs\node_......
  • js 中的 this
     <!DOCTYPEhtml><html><head><metacharset="UTF-8"><title>Inserttitlehere</title><scripttype="text/javascript">vartool={a:'somemsg',show:functi......