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
Release: 2023-03-02 12:52:01
Original
1179 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

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

Data assembled on the server side

<code>echo json_encode($var);</code>
Copy after login

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.

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template