PHP Return Value from Controller to Ajax -


I am using an MVC and I have one such button to remove an uploaded image Using an AJAX call for / P>

This is my model:

  public function remove_document ($ documentID, $ documentName) {$ objData = $ this- & gt; ObjDB - & gt; SetStoredProc ('attritionRemoveDocument') - & gt; SetParam ('documentID', $ documentID) - & gt; SetParam ('documentName', $ documentName) - & gt; ExecStoredProc () - & gt; ParseXML (); Return $ objData-> Data-> reaction; }   

The response back to this either is true or false .

Here's my controller:

  public function deleteFile () {// Get the document ID We $ $ documentID = $ this- & gt; Input-> Posting ('documentID'); $ DocumentName = $ this- & gt; Input-> Post ('documentName'); // Check that if the file is also here (file_exists ('./ upload /'.$ documentName)) {// Remove file unlink (' ./ upload / '. DocumentName); $ RemoveFile = $ this- & gt; Submit-model-> Remove_document ($ documentID, $ documentName); Return $ Remove File; }}   

And finally, my AJAX call:

  $ ('[name = deleteDocument]'). Click (function () {var documentID = $ (this) .attr ('documentID'), documentName = $ (this) .attr ('documentName'); // $ .jax delete image ({type: 'POST' , Url: '../deleteFile', datatype: 'xml', data: {'documentID': documentID, 'documentName': documentName}, success: function (msg) {// on success, delete current file section console .log (msg);}}};});   

When I give the echo to $ removeFile in the controller, give me the true / false value However, this is never seen in the success function of AJAX calls.

Any thoughts?

controller

if the result is true

  "Fine" echo   

If the result is false

  "no" in your view and in the part of success   < P> echo  
  success: function (msg) {if (msg = = "OK") {warning ("deleted"); } And {warnings ("not deleted"); }   

If you are using it with AJAX, then your controller should not return BOOL, your AJAX call should control the result by success method.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -