C
C
carbonate2016-02-19 20:33:22
JavaScript
carbonate, 2016-02-19 20:33:22

jQuery post json why no response?

1.php

var arr = {"token":"123"};
  $.ajax({
    url: '2.js',
    type: 'POST',
    data: JSON.stringify(arr),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    //async: false,
    success: function (r) {
      console.log('res');
        console.log(r);
    }
});

2.js How to get a response without removing / *xxx*/ ? (without them everything works)
/*xxx*/{"result":"1000"}/*xxx*/

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
carbonate, 2016-02-19
@carbonate

dataFilter: function(response) {
return response.replace("/*xxx*/","").replace("/*xxx*/","");
},

S
Stalker_RED, 2016-02-19
@Stalker_RED

as far as I understand, your POST request is not processed by the server? It just returns the contents of 2.js
And most likely the server is doing everything right, and your only problem is that /*xxx*/{"result":"1000"}/*xxx*/- is not a valid JSON.

M
MNB, 2016-02-19
@MNB

get how plain text
cut comments regex
parse as json

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question