• JQuery ajax 使用


    • JS 端

    function xxx_Write() 
    { 	
        var ajaxPostData = {"status": "ok"};
    
        send_ajax_data(ajaxPostData,
            function(data){
                console.info("AJAX recv " + data["status"] + ".");
            }
        );	
    } 
    
    function send_ajax_data(json_data, success_function)
    {
    
        if (success_function == null) {
            console.info("Please pass send_ajax_data function as argument.");
            return ;
        }
    
        $.ajax({
            url: "xxx_Write.php",
            type: 'POST',
            contentType:'application/json; charset=utf-8',
            data: JSON.stringify(json_data),
            dataType:'json',
            success: function(data){
                //On ajax success do this
                console.info("ajax back infomations success.");
                console.info(data);
    
                if (data["status"] == "ok"){
                    success_function(data);
                } else {
                    alert("Please Go To Console Get More Infomations.");
    
                    console.info(data);
                }
            },
            error: function(xhr, ajaxOptions, thrownError) {
                //On error do this
                //On error do this
                alert("Please Go To Console Get More Infomations.");
    
                console.info(xhr);
                console.info(ajaxOptions);
                console.info(thrownError);
            }
        });
    }
    
    • PHP 端 xxx_Write.php

    <?php header("Access-Control-Allow-Origin: *") ?>
    <?php
    
        $data = json_decode(file_get_contents('php://input'), true);
    
        echo json_encode($data);
    ?>
    
  • 相关阅读:
    UIPickerView-一.01-
    闭包-01-Swift
    Swift 入门-01-概述
    git使用命令行-01-自己操作的
    FetchedResultsController-03-CoreData相关
    SQLite-05-增删改查
    Sqlite函数总结-04
    List<string>转xml
    比较两个List<T>是否相同
    获取DataTable前几条数据
  • 原文地址:https://www.cnblogs.com/chenfulin5/p/13565583.html
Copyright © 2020-2023  润新知