8

In cloudpages, I've been trying to build a handler page for an ajax form POST that checks a certain DE to prevent duplicate submissions. It needs to return "duplicate entry, not saved" or "successfully saved" etc

I am aware that SSJS can set response headers, but it doesn't look like it can set status codes. Thus every request comes back with status: 200 even if the body of the response contains error information.

I have tried using a JSON code resource type, but I can't get SSJS to modify anything "lower level" than response headers.

How exactly can I return a "form post fail: duplicate entry exists" status code to my Jquery ajax form submit page?

1
  • 2
    Why not just parse the result in your handler page and return the appropriate string to the calling page? Nov 14, 2017 at 15:53

1 Answer 1

1

Not entirely sure that this would work, but you could try the SSJS RaiseError function, here's an example:

<script runat="server">     
 var StatusAndRequestID = [0,0];
 var newObject = Platform.Function.InvokeCreate(CreateRequest,StatusAndRequestID,Options);
 var status = StatusAndRequestID[0];
 var requestID = StatusAndRequestID[1];     if(Result != "OK") {
 Platform.Function.RaiseError("Create failed. Ensure your call successfully invoked the Create method.",false,"statusCode","3");
     }
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.