php-sp-api icon indicating copy to clipboard operation
php-sp-api copied to clipboard

call a stored proc

Open EliShklovsky opened this issue 8 years ago • 3 comments

Hi I'm trying to find my first steps in php_crud, which is quite self explenatory. I was also trying this php-sp-api which I could not understand how to use it. I will appreciate any explanation, Regards and thanks Eli

EliShklovsky avatar May 16 '17 10:05 EliShklovsky

Here is a simple JavaScript code that worked for me.

var divResult = document.getElementById("divResult");
var txtUserId = document.getElementById("txtUserId");

//Build the JSON Data Object to Send to Server
var data = {};
data.user_id = txtUserId.value;
var params = new URLSearchParams(data);

//Create the Http Request
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
	if (this.readyState == 4) {
		if (this.status == 200) {
			//Success. Display Result here
			divResult.innerHTML = this.responseText;
		}
		else {
			//Error. Display Error Message here
			divResult.innerHTML = this.responseText;
		}
	}
};

xhttp.open("POST", "/api.php/get_post_count_for_user", true);
xhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhttp.send(params);

cherianmpaul avatar Oct 02 '19 16:10 cherianmpaul

@mevdschee I have the entire working code... Do you want me to send a pull request? We can put it as a sample code.

cherianmpaul avatar Oct 02 '19 16:10 cherianmpaul

@cherianmpaul that would be wonderful! You could make a examples/clients folder in which you implement a client (as I've done in the php-crud-api project).

https://github.com/mevdschee/php-crud-api/tree/master/examples/clients

I'm happy to merge any pull request, make sure you register at Hacktoberfest, see: https://hacktoberfest.digitalocean.com (you may earn a t-shirt).

mevdschee avatar Oct 02 '19 17:10 mevdschee