如何使用jquery将此数据从本地存储发送到php

时间:2017-12-09 23:42:07

标签: javascript php jquery local-storage

这是我收到的php代码并将数据插入在线数据库。我非常确定我这些捏造的代码不起作用,但随着你的教育和帮助,我会得到。谢谢。 insertdata.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);
?>

1 个答案:

答案 0 :(得分:0)

您可以这样做:

let url = Bundle.main.url(forResource:"hello", withExtension: "plist")!
let plistData = try! Data(contentsOf: url)
let swiftArray = try! PropertyListSerialization.propertyList(from: plistData, format: nil) as! [[String:String]]
let matchingTerms = swiftArray.filter({ $0["kurdi"]!.range(of: "oo", options: .caseInsensitive) != nil })
print(matchingTerms)

顺便说一下,你可能想让$(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); } }); }); 变量全局并分配一次,然后你可以从两个函数中调用它。