Skip to content
Advertisement

how to get the responseText from echo in php

I’m trying to return a value from PHP to JavaScript through responseText. The idea is if mysqli_num_rows($rslt) != 0, responseText = 1, or if mysqli_num_rows($rslt)= 0, to do an insert and responseText = 0, and then in JavaScript I get the responseText. How can I achieve that, because I tried with echo, but I couldn’t find a solution.

JavaScript code:

JavaScript

PHP code:

JavaScript

Advertisement

Answer

Perhaps the following might help – I rearranged things a little and corrected the js functions and sent a basic JSON string as the responseText for convenience

JavaScript
Advertisement