zoukankan      html  css  js  c++  java
  • jquery的ajax和jsonp的写法

    交互 ajax jsonp
    ajax跟之前一模一样
    $(document).ready(function(){
        $.ajax({
            url:'get.php',
            type:'get', //或者写'post'
        timeout:"3000",
            cache:"false",
            data:{
                a:12,
                b:5
            },
            success:function(str){
                alert(str);
            },
            error:function(err){
                alert(err);
            }
        });
    });
    注意:向后台传一个json的写法
    $.ajax({
    url: URL+'/tasks/task',
    type: 'PUT',
       chache:"false",

    contentType: "application/json",
    data: JSON.stringify({
    data: {
    "key":"value"
    }
    }),
    dataType: "json",
    success:function(str){
    if(str.errcode==0){
    //发送数据成功
    }
    },
    error:function(err){
    alert(err);
    }
    });

     
    jsonp
    $(document).ready(function(){
        $.ajax({
    url:'https://sp0.baidu.com/5a1Fazu8AA54nxGko9WTAnF6hhy/su',
            dataType:'jsonp',
            jsonp:'cb',
            data:{
                wd:'XX.value'
            },
            success:function(result){
                alert(result.s);
            } ,
            error:function(err){alert(err)}
        });
    }); 
  • 相关阅读:
    sqli-libs(38-41(堆叠注入)关)
    Vue 短信验证码逻辑
    promise(二)
    js类型转换
    微信小程序的组件传值
    微信小程序首页跳转详情页
    微信小程序的事件绑定
    微信小程序简介
    webpack4入门教程十分钟上手指南
    Vue 全局注册组件和局部注册组件
  • 原文地址:https://www.cnblogs.com/sweeeper/p/6106251.html
Copyright © 2011-2022 走看看