Ajax-PHP interface problems

Source: Internet
Author: User
I want to make a simple page display statistics. The Cainiao front-end won't. I wrote a small case and ran it on github. I would like to ask all the experts for advice. Ajax: {code...} json: {code...} php: {code...

I want to make a simple page display statistics. The Cainiao front-end won't. I wrote a small case and ran it on github. I would like to ask all the experts for advice.

Ajax:

$.ajax({    url: 'php/index.php',    type: 'get',    dataType: 'json',    data: {},}).done(function(dat) {    console.log("2");    $(".header").html(dat.vp);})   .fail(function() {    console.log("error");}).always(function() {    console.log("complete");});

Json:

{    "vp":"0"}

Php:

 
  

The idea is that every time a page is accessed, a request is made, and PHP reads and writes the json record count (the database does not ). However, every time an ajax request enters fail. However, the PHP request status code is 200.


How can I output the entire file?

Reply content:

I want to make a simple page display statistics. The Cainiao front-end won't. I wrote a small case and ran it on github. I would like to ask all the experts for advice.

Ajax:

$.ajax({    url: 'php/index.php',    type: 'get',    dataType: 'json',    data: {},}).done(function(dat) {    console.log("2");    $(".header").html(dat.vp);})   .fail(function() {    console.log("error");}).always(function() {    console.log("complete");});

Json:

{    "vp":"0"}

Php:

 
  

The idea is that every time a page is accessed, a request is made, and PHP reads and writes the json record count (the database does not ). However, every time an ajax request enters fail. However, the PHP request status code is 200.


How can I output the entire file?

Open the index. php request and check whether the response meets the requirements.

Php interpreter execution.
Install a wamp and try again.

The returned json data is obviously an object, but it must be accessed using arrays.
$ Data ['VP'] = intval ($ data ['VP']) + 1; changed to $ data-> vp = $ data-> vp + 1;
My answer is absolutely correct. do not believe it.

This should be because the web server configuration is incorrect and the PHP file is not parsed.

Github does not have any server environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.