Matt Hannam Matt Hannam - 10 months ago 94
Ajax Question

How to send an Ajax POST request

I'm using this code to send a POST to my node API to generate a PDF, my node console gives me these errors:

var request = $.ajax({
type: "POST",
url: 'http://localhost:8080/api/v1/generate',
data: {doc:"<h1>test 123</h1>"},

info: TypeError: null is not an object (evaluating 'child.transform')
info: info: phantomjs://code/shim.js:157 in transform info:

phantomjs://code/shim.js:138 in read

When I send a POST (with the Postman tool), the PDF is rendered and everything works.

localhost:8080/api/v1/generate?doc=<h1>testing 123</h1>

What am I doing wrong on my POST request?


Probably you need/can achieve it easier with formData


data = new FormData();
data.append( 'doc', "<h1>test 123</h1>" );

    url: 'http://localhost:8080/api/v1/generate',
    data: data,
    processData: false,
    type: 'POST',
    success: function ( data ) {
        alert( data );