0

I use ajax to send form data to php script which save this data into mysql table. Here is jQuery

var postAction = $(form).attr('action');
$.ajax({
    type: "POST",
    url: postAction,
    data: $(form).serialize(),
    success: function (data) {

    }
});

This php script after insert data to mysql return html code.

<?php
    $query=mysql_query("INSERT INTO table ('id','name') VALUES ('".$id."','".$name."'); 
    if($query) echo "OK";
    else echo "ERROR";
?>

Now i need result of this php script ('OK' or 'ERROR') use in success function.

It is possible?

6
  • stackoverflow.com/questions/11650160/… Your code must work ! Commented Dec 17, 2015 at 17:41
  • Or you want to show if insert it's ok in js ? Commented Dec 17, 2015 at 17:44
  • I want success function get result of php script, and use this result on page where the form was submited ex. $('div').html(data); Commented Dec 17, 2015 at 17:48
  • But you already have it! The data contains "OK" or "ERROR", so you can do whatever you want with those responses ! Commented Dec 17, 2015 at 17:55
  • You got right. Sorry for my carelessness at work with my script :( Its my fault. In php script i include data which produce error. But what is weird, include same data in other script files dont make any error. Commented Dec 17, 2015 at 18:17

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.