Friday 9 June 2017

Ajax success don't execute with node js

success don't response, I have used this code:

Client code:

function add(){
    var values = formserial(addd);
    var tok = "abc",
    var url= 'http://localhost:8181/add';
        $.ajax({
            type: "POST",
            url:url,
            dataType: "json",
            data:{ss:values,tok:tok},
            success: function(response){
                alert(response);        
            },
            error: function(jqXHR, textStatus, err) {
                alert('text status '+textStatus+', err '+err)
            }
        });
}

Server code:

    router.route('/add')
    .post(function(req, res) {
      res.header("Access-Control-Allow-Origin", "*");
      res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
      res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");

      res.json("New added!");
      console.log(""New added!");
    });

The console show "New added" but the success don't alert response. Any solution please ?



via ahmed

No comments:

Post a Comment