ไฟล์ php
โค้ด: เลือกทั้งหมด
if(isset($function_word) && $function_word == 'word_character')
{
header('Content-Type: application/json;');
$f = file_get_contents('styles\prosilver\template\Ciunt_Cha_API.postman_collection.json');
$jarr = json_code($f);
$nameapi = $jarr['item'][2]['response']["name"];
$wordapi = $jarr['item'][2]['response']["word"];
if($check == 1)
{
$value = array(
'name' => $nameapi,
'word' => nl2br($wordapi),
'date_word' => $user->format_date(time()),
);
$sql_arr = array(
'name' => $nameapi,
'word' => nl2br($wordapi),
'character_underscore_create_date' => time(),
'character_user_ip' => $ip,
);
$sql = 'INSERT INTO ' . 'tools_word_and_character_count' . ' ' . $db->sql_build_array('INSERT', $sql_arr);
$result = $db->sql_query($sql);
echo json_encode($value, JSON_UNESCAPED_UNICODE);
}
elseif ($check != 1)
{
$value = array(
'name' => $nameapi,
'word' => nl2br($wordapi),
'date_word' => $user->format_date(time()),
);
echo json_encode($value, JSON_UNESCAPED_UNICODE);
}
exit();
}
โค้ด: เลือกทั้งหมด
<script>
var check1 = 1
function myFunction() {
if (check1 == 1) {
check1 = 0
}
else {
check1 = 1
}
}
$(document).ready(function(){
$('#submit').click(function() {
var name1 = document.getElementById("input-user").value;
// console.log("ชื่อผู้ใช้ ", name1);
var word1 = document.getElementById("word_character").value;
// console.log("คำที่ต้องการส่ง ", word1);
var check2 = check1;
// console.log("ค่าที่ต้องการบันทึก ", check2);
if(name1 == "" && word1 == "") {
alert('{L_NAME_USER_WORD_AND_CHARACTER}');
name.focus();
word.focus();
return false;
}else if (name1 == "" ) {
alert('{L_NAME_USER_WORD}');D
name.focus();
return false;
}else if (word1 == "" ) {
alert('{L_USER_WORD_AND_CHARACTER}');
word.focus();
return false;
}else {
document.getElementById('submit').className = "loader";
$.ajax({
type: "POST",
url: './tools_word_and_character.php',
data: {
name:name1,
word:word1,
check:check2,
function_word_character:'word_character',
},
success: function(data){
$("#username_word").html(data.name);
$("#word").html(data.word);
$("#date").html(data.date_word);
document.getElementById('show_area_all').style.display="block";
document.getElementById('recnet-access').style.display="block";
document.getElementById('cp-main').style.display="none";
document.getElementById('submit').className = "linkback";
console.log(data);
},
});
}
return false;
});
});
</script>
โค้ด: เลือกทั้งหมด
{
"info": {
"_postman_id": "dcae7c78-ff29-4101-a63f-3823d98deca9",
"name": "Ciunt_Cha_API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "19986305"
},
"item": [
{
"name": "Get-/getstartpage",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8000/getstartpage",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"getstartpage"
]
}
},
"response": "name"
},
{
"name": "Get-/getstart1",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://127.0.0.1:8000/getstart1",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"getstart1"
]
}
},
"response": "name"
},
{
"name": "Post-/cutword",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{ \"word\": \"แซม ไวคิด python\", \"name1\": \"แซม\", \"check\": \"1\" }",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8000/cutword",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"cutword"
]
}
},
"response": { "word": "แซม ไวคิด python", "name": "แซม", "check": "1" }
},
{
"name": "Post-/cut",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{ \"check\": \"1\" }",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8000/cut",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"cut"
]
}
},
"response": "name"
},
{
"name": "Post-sent Id",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{ \"id\": \"1\"}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8000/getDatabyId",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"getDatabyId"
]
}
},
"response": "name"
},
{
"name": "Post-/page",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "{ \"curPage\": \"2\" }",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://127.0.0.1:8000/page",
"protocol": "http",
"host": [
"127",
"0",
"0",
"1"
],
"port": "8000",
"path": [
"page"
]
}
},
"response": "name"
}
]
}