datasource and catch response

I have one form that submit dats to php script.
the code in doubt is:
agentsDS.dataURL= “myurl.php?parameters…”
agentsDS.fetchData();

the myurl.php works fine, the database stores the info, and eveything is ok, but the idea is my myurl.php echoes one value, can be OK or ERROR, just to indicate the transacion was made fine or not.
I need to catch this value (OK or ERROR) just to notify the user the transaction was successfull or not.
I know is a simple question, but I’m confused about it.
if any can help will be appreciated,
regards,

If you’re using a RestDataSource, return a response that has a negative status code and provide the error message a response.data.

If you’ve got some pre-existing service you’re connecting to, see eg this example for how you could use transformResponse to fill in a DSResponse object with errors your server is returning.

how can I return a response that has a negative status code and provide the error message a response.data
my php simply puts the data into database.
it doesn’t print anything as output yet.
can you put one line in example of how can I create the negative status code..?

See previous response:

Now you need to either look at the RestDataSource docs (if that’s what your using) or the provided example.

please, I’ve seen the docs hundreeds of times.
I can’t make it work.
can you please post here what’s wrong?
my code is as follows:
isc.DataSource.create({
ID: “agentsDS”,
dataFormat: “json”,
dataURL: “myUrl.php”,
showPrompt: false,
fields:[
{name:“department”, title:“<?php echo $textos[3];?>”, type:“text”, width:150},
{name:“name”, title:“<?php echo $textos[4];?>”, type:“text”, width:166}
]
});

then, later in code I make the insert as result of click button as follows:
agentsDS.dataURL = “myUrl.php?department=sales&name=john”;
agentsDS.fetchData();

my php is as follows:
<?php
$cons=“INSERT INTO users (department, name) VALUES (”.urldecode($department)." , “.urldecode($name).”)";
$recordset = mysql_query($cons,$conn) or die(mysql_error());
?>

that’s all, my php prints nothing.
so, the idea is how can I generate ok result to catch if from my fetchData in my submiting page?
please, if you can answer me with the code, not with more questions, I’m really confused about it and I need to make it work.
best regards,

So again, the RestDataSource provides a pre-built protocol that tells you exactly what to return. Mysteriously, you have chosen not to use RestDataSource, which gives you the exact response formats right in the docs, as well as a complete running sample of all 4 operationTypes, but you are demanding to be told exactly what to return…

We suggest you switch to the RestDataSource and just copy the sample.

ok isomorphic, you are right, it was my mistake.
In my code:
isc.DataSource.create({
should say:
isc.RestDataSource.create({

I was solved now, and it works like a charm !.
obviously you know what you are talking about.
I apologize.
now I have another question about the same point, so I decide to post in this thread too.
now, everything is going fine, but:
my php code prints the following:
{response:{status: -4, data:[{xxx:“OK”}]}}
in my page, I have the following code in the RestDataSource
transformResponse : function (dsResponse) {
isc.say(dsResponse.data[0].xxx);
isc.say(dsResponse.status);
}
dsResponse.data[0].xxx prints OK as expected.
but dsResponse.status always print 0, even when I set it to -4.
the idea is to force -4 error, just to understand how does it works.
any idea?
once again, thanks for your support !.
regards,

No problem.

Your transformResponse should call Super(), as in:

    this.Super("transformResponse", arguments);
    isc.logWarn("status is: " + dsResponse.status);

By not calling Super() you actually destroy all of the response-processing logic of RestDataSource, which is in transformResponse.

Don’t use isc.say() to output debugging information. Use the Developer Console and logWarn().

You probably don’t want to use status -4, which is specifically for validation errors, and will cause eg a DynamicForm or editable ListGrid to look for validation errors as part of dsResponse.errors.