Saturday 13 October 2018

Native XMLHttpRequest

var newName = 'John Smith',
    xhr = new XMLHttpRequest();

xhr.open('POST', 'myservice/username?id=some-unique-id');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() {
    if (xhr.status === 200 && xhr.responseText !== newName) {
        alert('Something went wrong.  Name is now ' + xhr.responseText);
    }
    else if (xhr.status !== 200) {
        alert('Request failed.  Returned status of ' + xhr.status);
    }
};
xhr.send(encodeURI('name=' + newName));

Credit: https://blog.garstasio.com/you-dont-need-jquery/ajax/#posting
Test:https://www.measurethat.net/Benchmarks/ShowResult/13128

Thursday 24 March 2016

รวม Code แก้ไข wordpress

Deactive plugin all at database

- UPDATE wp_options SET option_value = 'a:0:{}' WHERE option_name = 'active_plugins'

Loading .....


Monday 8 June 2015

Code ที่ใช้บ่อยแต่ Copy มาใช้จนลืมแปะไว้รวมๆ ขี้เกรียจหา

// AJAX EX. ส่งข้อมูลแบบ POST หรือต้องการ GET ก็แค่เปลี่ยน Type
dataType ที่ผมใช้ก็มี html กับ JSON นี่ละ
beforeSend ฟังค์ชั่น ไว้ทำอะไรก่อนการส่งข้อมูล เช่นแสดงภาพ load animation
ไว้เก่งแล้วจะอธิบายเพิ่ม เอาที่ผมเข้าใจไว้ใช้งานจริงล้วนๆ
$.ajax({
type: "POST",
url: "/path",
dataType: "html",
data: ({id:id,lang:lang}),
beforeSend: function(  ) {
$(".show-load").show();
},
success: function(data) {
if(data!="NULL")
{
                                return true;

}else{

return false;
}
},
error: function( req, status, err ) {
console.log( 'Something went wrong', status, err );
}
});
//GET POST ส่งแบบ get หรือโพสไปตรงๆ เลย
$.post( "/path", {lang:$(this).attr('href')} );