【问题标题】:how to send this data from local storage to php online using jquery如何使用 jquery 将这些数据从本地存储发送到 php 在线
【发布时间】:2018-05-23 21:11:18
【问题描述】:

这是我接收数据并将数据插入在线数据库的 php 代码。我很确定我这些捏造的代码不会起作用,但有了你的教育和帮助,我会得到。谢谢。插入数据.php

<?php
include 'connect.php';
include 'function.php';
//Create Object for DB_Functions clas
$db = new DB_Functions(); 
//Get JSON posted by Android Application
$json = $_POST["usersJSON"];
//Remove Slashes
if (get_magic_quotes_gpc()){
$json = stripslashes($json);
}
//Decode JSON into an Array
$data = json_decode($json);
//Util arrays to create response JSON
$a=array();
$b=array();
//Loop through an Array and insert data read from JSON into MySQL DB
for($i=0; $i<count($data) ; $i++)
{
//Store User into MySQL DB
$res = $db->storedata($data[$i]->callid,$data[$i]->pid,$data[$i]->pname,$data[$i]->medstay_amt,$data[$i]->med_amt,$data[$i]->imv_amt,$data[$i]->othermc_amt,$data[$i]->emtrans_amt,$data[$i]->outpden_am,$data[$i]->otherps_amt,$data[$i]->herb_amt,$data[$i]->medban_amt,$data[$i]->othermp_amt,$data[$i]->assist_amt,$data[$i]->code,$data[$i]->date);
    //Based on inserttion, create JSON response
    if($res){
        $b["id"] = $data[$i]->pid;
        $b["status"] = 'yes';
        array_push($a,$b);
    }else{
        $b["id"] = $data[$i]->pid;
        $b["status"] = 'no';
        array_push($a,$b);
    }
}
//Post JSON response back to Android Application
echo json_encode($a);
?>

【问题讨论】:

  • 我看到你在使用 jQuery,看看这里:api.jquery.com/jquery.ajax
  • 感谢您的更正和快速响应。我会看看然后回来。
  • 对不起,我还是个新手。不幸的是,我无法根据页面内容创建自己的代码。请是否可以使用我的代码来帮助我完成它
  • 点击.BTN_Submit_Task.BTN_Sub后是否要发送请求?你想传递什么数据? AllTasks 对象?
  • 是的,先生。请帮我 。单击按钮后,记录应发送到我的 php Web 应用程序页面。数据库表名是问题。谢谢

标签: javascript php jquery local-storage


【解决方案1】:

你可以这样做:

$(document).on("click", ".BTN_Submit_Task", function () {
    var AllTasks = ls.GetAllArr(LocalstorageName);
    var id = $(this).attr("rec_id");
    var result = $.grep(AllTasks, function(e){ return e.rec_id === id; });    

    $.ajax({
        url: "url/of/php/file.php",
        type: 'post',
        dataType: 'json',
        data: {usersJSON: [result]},
        done: function(response) {
            console.log(response);
        }
    });
});

顺便说一句,您可能希望将 AllTasks 变量设为全局变量并分配一次,然后您可以从两个函数中调用它。

【讨论】:

  • "SyntaxError: Unexpected token )" 来自控制台的第二行但最后一行
  • @BernardLogonia 已修复,立即尝试。
  • @BernardLogonia 它解决了你的问题吗?如果是,请接受此答案,以便将其标记为已解决。
猜你喜欢
  • 2018-06-15
  • 2015-10-27
  • 2016-07-21
  • 2021-11-24
  • 2018-09-24
  • 2019-08-04
  • 2013-01-31
  • 2019-01-07
  • 2018-05-06
相关资源
最近更新 更多