Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common minor problems in Ajax

Shulou Source: shulou.com Published: 2022-06-03 14:15:14 10月03日 Update

This article mainly shows you "what are the common minor problems in Ajax". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the common minor problems in Ajax?"

The 1.ajax cross-domain passing value is required. The type of return is jsonp.

$.ajax ({url: "http://.......",type: 'GET',dataType:' JSONP',//js cross-domain value success: function (data) {}}))

DataType

Type: String

The type of data expected to be returned by the server. If not specified, jQuery automatically determines intelligently based on the MIME information of the HTTP package, such as the XML MIME type is recognized as XML. In 1. 4, JSON generates a JavaScript object, and script executes the script. Then the data returned by the server side will be based on the

After this value is parsed, it is passed to the callback function. Available values:

"xml": returns the XML document, which can be processed with jQuery.

"html": returns plain text HTML information; the included script tag is executed when the dom is inserted.

"script": returns plain text JavaScript code. The results are not automatically cached. Unless the cache parameter is set. Note: when making remote requests (not in the same domain), all POST requests will be converted to GET requests. (because the script tag of DOM will be used to load)

"json": returns JSON data.

"jsonp": JSONP format. When calling a function in the form of JSONP, such as "myurl?callback=?" Will jQuery be replaced automatically? Is the correct function name to execute the callback function.

A demo sample of 2.ajax works with php to get the value.

$(function () {var my_data= "foreground variable"; my_data=escape (my_data) + ""; / / coding to prevent Chinese characters from garbled $.ajax ({url: "ajax_php.php", type: "POST", data: {trans_data:my_data}, / / dataType: "json", error: function () {alert ('Error loading XML document');}, success: function (data,status) {/ / if php is successfully called alert (unescape (data)) / / Decoding, displaying Chinese characters}});})

Php code

$backValue=$_POST ['trans_data']; echo $backValue. "+ backend return"

Data conversion processing of json in 3.php

Json_decode (string $json [, bool $assoc]); / / accepts a string in JSON format and converts it to a PHP variable

Json_decode ($data,true)

Json A string in json string format to be decoded. Assoc when this parameter is TRUE, it returns array instead of object.

Json_encode (mixed $value [, int $options = 0]) returns the JSON form of the value value

Json_encode ($a)

The above is all the contents of the article "what are the common problems in Ajax?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Function data type common problem content format article code information parameter variable character string form text server label Chinese character processing Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple vpn MariaDB MySQL