Get a free trial // Grow your CSS skills // Land your dream job

Post and Get data from JS to PHP

  • # February 6, 2013 at 10:41 am


    this the first time i’m create a server side so i’m kinda lost in here.. :)

    i want to from my client side to send the data to the server and the server validate the data and send back the response.

    so i found something like this when i was searching

    function submitData() {
    console.log(‘Sending Data’);
    var JSONObject = {};
    var url = ‘http://mywebsite/server/’

    // construct an HTTP reques
    var xhr = new XMLHttpRequest();‘POST’, url, true);
    xhr.setRequestHeader(‘Content-Type’, ‘application/json; charset=UTF-8’)

    // send the collected data as JSON

    xhr.onloadend = function () {
    //check the result & error messages


    i’m need help :(

    thanks in advance.

    # February 6, 2013 at 10:21 pm

    … what is your question?

    # February 18, 2013 at 5:17 pm

    I have no idea how to submit form with native js.

    in jQuery you can use $.post or $.get

    $.post(‘process.php’, {field1: “value”, field2: “value”}, function(result){ //result is response from process.php, such as echo $value etc. });

    hope it helps.

    # February 21, 2013 at 8:09 am

    Hello friend
    this is also one of the code for js to php

    < ?php
    // … php code …
    echo ‘‘;

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed