7:00 – 5:00 ASRC MKT
- Aaron’s ot BoP today
- Working on JuryRoom, particularly hooking up PHP to Angular
- Here’s the hello world php app that’s working:
<?php header('Access-Control-Allow-Origin: *'); echo '{"message": "hello"}';
- And here’s the Angular side:
uploadFile(event) { const elem = event.target; if (elem.files.length > 0) { const f0 = elem.files[0]; console.log(f0); const formData = new FormData(); formData.append('file', f0); this.http.post('http://localhost/uploadImages/script.php', formData) .subscribe((data) => { const jsonResponse = data.json(); // this.gallery.gotSomeDataFromTheBackend(jsonResponse.file); console.log('Got some data from backend ', data); }, (error) => { console.log('Error! ', error); }); } }
- Here’s how to connect to the deployment server for debugging (I hope!). From Importing settings from a server access (deployment) configuration:
- Can’t see the post info coming back, so I really need to get the debugger set up to talk to the server. Following these directions: Web Server Debug Validation Dialog. Here’s the dialog with some warnings to be corrected:
- Note that you HAVE TO RESTART APACHE for any php.ini changes to take
- Had to Add XDebug Helper Chrome Extension. That helped with the php running in the browser, but not in the call to PHP from angular
- Works in Postman, but it doesn’t fire the debugger. Still, at least I know that the data can get to the php. Not sure if angular is sending it. Here’s the postman results:
- Here’s the debugger view. The data appears to be going up (formData), but it’s not coming back in the echo like it does in postman. I’ve played around with Content-type, and that doesn’t seem to help:
- In the network view, we can see that the payload is there:
- So it must not be getting accepted in the PHP….