View Issue Details

IDProjectCategoryView StatusLast Update
0019524phpList 3 applicationAll Otherpublic07-11-18 09:56
Reportermaltfield 
PrioritynormalSeverityminorReproducibilityhave not tried
Status resolvedResolutionopen 
Product Version 
Target Version3.3.6Fixed in Version 
Summary0019524: return error code on FAIL in ajax subscribe
DescriptionThis is apparently a long-standing issue with the community-recommended way for users to be able to add subscribers to phplist from an external domain using ajax in phplist3 as described in this thread:

 * https://discuss.phplist.org/t/ajax-subscribe-api/974

The code in the zip file attached to the above thread uses jquery's ajax function, and it defines a function success() that's triggered when the ajax call succeeds and a error() function that's triggered when the ajax call failed. The problem is: phplist merely prints "FAIL" in the response when the subscribe attempt fails, but the status code remains a 200.

IMHO, the ajax form should not have to search for the string "FAIL" in the response in order to detect a failure. Instead, it should check the status code of the HTTP response from the server. This can be achieved, for example, by throwing an exception in PHP--which will make PHP return a 500 Internal Server Error.

Here is the relevant code for handling ajax subscription queries on phplist's side:

 * https://github.com/phpList/phplist3/blob/7ec8ab78f215894c29da8e54ff9d7c41ffde64c6/public_html/lists/index.php#L242-L272

My recommendation is to add the line:

    throw new Exception( "Error: Subscribe attempt failed!" );

after the "echo 'FAIL';" line here:

 * https://github.com/phpList/phplist3/blob/7ec8ab78f215894c29da8e54ff9d7c41ffde64c6/public_html/lists/index.php#L270
TagsNo tags attached.

Relationships

related to 0019525 new Provide error message when a subscribe page accessed via Ajax doesn't exist 

Activities

maltfield

02-11-18 19:53

reporter   ~0061320

I created a PR request for this here:

 * https://github.com/phpList/phplist3/pull/432