Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've created a PHP function which is hosted on a web server. The code here is designed to allow the user to create a user account which requires their forename, surname, email and password. I can use Apigee to submit the data, so I know that everything works. A snapshot of my code is below:

function student2_post() {
    $this->load->database();
    $StudentID = $_POST['StudentID'];
    $StudentForename = $_POST['StudentForename'];
    $StudentSurname = $_POST['StudentSurname'];
    $StudentEmail = $_POST['StudentEmail'];
    $StudentPassword = $_POST['StudentPassword'];
    $info = array('StudentID'=>null, 'StudentForename'=>$StudentForename, 'StudentSurname'=>$StudentSurname, 'StudentEmail'=>$StudentEmail, 'StudentPassword'=>$StudentPassword);
    $this->db->insert('StudentLogin', $info);
    $data->StudentID = $StudentID;
    $data->StudentForename = $StudentForename;
    $data->StudentSurname = $StudentSurname;
    $data->StudentEmail = $StudentEmail;
    $data->StudentPassword = $StudentPassword;
    $this->response($data, 200);
    }

My next step of development is to try and develop an "app" or a mobile service which allows me to use my own GUI. My code for this is below:

<!-- Home -->
<div id="page2" class="ui-bar-a" data-role="page">
    <div data-role="header" data-theme="320CT_Coursework.min">
        <h3>
            320CT
        </h3>
    </div>


    <div data-role="content">


    <div data-role="fieldcontain" id="StudentID">
            <fieldset data-role="controlgroup">
                <label for="StudentID">
                    Name
                </label>

                <input name="" id="StudentID" placeholder="" value="" type="text">
            </fieldset>
        </div>


        <div data-role="fieldcontain" id="StudentForename">
            <fieldset data-role="controlgroup">
                <label for="StudentForename">
                    Surname
                </label>
                <input name="" id="StudentForename" placeholder="" value="" type="text">
            </fieldset>
        </div>


        <div data-role="fieldcontain" id="StudentSurname">
            <fieldset data-role="controlgroup">
                <label for="StudentSurname">
                    Email
                </label>

                <input name="" id="StudentSurname" placeholder="" value="" type="text">
            </fieldset>
        </div>


        <div data-role="fieldcontain" id="StudentPassword">
            <fieldset data-role="controlgroup">
                <label for="StudentPassword">
                    Password
                </label>
                <input name="" id="StudentPassword" placeholder="" value="" type="text">
            </fieldset>
        </div>


        <input type="submit" value="Submit">


    </div>
    <div data-role="footer" data-theme="a" data-position="fixed">
        <h3>
        </h3>
    </div>
</div>

This works and brings up a GUI for me to enter data in, however obviously it doesn't link up. I've got all the form elements there I need, with IDs which is kosher to the PHP function.

I've been unable to find any resources which allow me to use the PHP function *student2_POST* in my jQuery code. Everything I find seems to be related to non-PHP functions.

TLDR: I have a function hosted on a web service which submits a form and I need a way to implement this function in jQuery. Thank you in advance for your help!

share|improve this question

2 Answers

You are looking for: $.ajax or $.post

share|improve this answer

In order to communicate between client (html / js) and server (php), you need to execute an HTTP request.

This may tipycally be done using an HTML form, or dynamically using AJAX methods such as (for JQuery) :

  • $.ajax( url [, settings ] )

    Perform an asynchronous HTTP (Ajax) request.

  • $.post( url \[, data \] \[, success(data, textStatus, jqXHR) \] \[, dataType \] )

    Load data from the server using a HTTP POST request.

share|improve this answer
Thank you Geoffroy, I'm assuming that I'd have to use this example $.post("test.php", $("#testform").serialize()); Question 1: How would I give an ID to my form? Currently it's just on a page Question 2: How would I then connect up the POST to the submit button? – Jonny Bird Mar 12 at 17:17
@JonnyBird And ID to your form? What for ? And add a onclick listener on your button to call the $.post method :) – Geoffroy Mar 12 at 17:25
Well the example has "#testform" which I assumed was some sort of ID? And I'm completely lost with the onclick listener..the examples there don't seem to link up with a button, just with text?? – Jonny Bird Mar 12 at 17:48
1  
I think you should study html first, it will be better for you. Sorry but I can't do everything for you. You should know at least a bare minimum about HTML / DOM / Javascript and events before using JQuery and making HTML web pages. – Geoffroy Mar 13 at 0:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.