Home  >  Article  >  Backend Development  >  The result obtained from the data requested by PHP ajax is in Html format, which is the html of the current page. It cannot be converted into json. Please crack it.

The result obtained from the data requested by PHP ajax is in Html format, which is the html of the current page. It cannot be converted into json. Please crack it.

WBOY
WBOYOriginal
2016-12-01 01:27:441179browse

This is the code. The format of dataType must be changed to html to obtain the data, otherwise an error 200 will be reported. $.ajax({

<code>                                type:"POST",
                                async:false,
                                url:"<?php echo $this->generateURL('Film.Index', array('save'));?>",
                                data:dataparam,
                                dataType:"json",
                                success:function(msg){</code>

Reply content:

This is the code. The format of dataType must be changed to html to obtain the data, otherwise an error 200 will be reported. $.ajax({

<code>                                type:"POST",
                                async:false,
                                url:"<?php echo $this->generateURL('Film.Index', array('save'));?>",
                                data:dataparam,
                                dataType:"json",
                                success:function(msg){</code>

Set the header on the server side, there must be no output before the header

<code>header('Content-type: application/json');</code>

Data assembled on the server side

<code>echo json_encode($var);</code>

This is caused by your server not returning the JSON format you expected. Please print the server output and see.

That is because the data returned by the server is not in json format, and it is not a front-end problem.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn