-1

I have a php file that do my validate, I have a html where I write my input and I have a js file that will link the html and the php using ajax. My question is how can I get the value from my textbox and put it in my js that will go to the php do the validation

$.ajax({
            type:"post",
            url: "https://csunix.college.ca/140065/f15/validation.phps?act=default",
            data: {jsObject},
            dataType: "json",
            success: function(data){
                alert("all good");
            },
            error : function(data){
                alert("Something happen");
            }
        });

1 Answers1

0

Get the input field value and put it into the data: option:

$.ajax({
    url: "https://csunix.college.ca/140065/f15/validation.phps?act=default",
    data: {fieldname: $("#inputid").val()},
    dataType: "json",
    type: "post"
    success: function(data){
        alert("all good");
    },
    error : function(data){
        alert("Something happen");
    }
});

In the PHP script, use $_POST['fieldname'] to get the input value that needs to be validated.

Barmar
  • 741,623
  • 53
  • 500
  • 612