Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the problem of getJSON Cross-domain SyntaxError

Shulou Source: shulou.com Published: 2022-06-03 09:03:48 10月02日 Update

This article mainly explains "how to solve the cross-domain SyntaxError problem of getJSON". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the cross-domain SyntaxError problem of getJSON".

The javascript code is as follows:

(".check _ mobile") .click (function () {var mobile = $('.mobile'). Val (); $.getJSON ("http://www.test.com/user.php?mobile="+mobile+"&format=json&jsoncallback=?", function (data) {if (data.succ = = 1) {var html ="; $(".r _ m") .append (html);});})

The user.php code is as follows:

The response is as follows:

Here's the problem:

In Firefox: SyntaxError: missing; before statement

The solution is as follows:

Header ("Access-Control-Allow-Origin:http:www.test.com"); $b = json_encode ($return); echo "{$_ GET ['jsoncallback']} ({$b})"; exit

Finally, the complete code:

Tags: Questions codes browsers learning browsing content Firefox Shijiazhuang Yuecheng Shijia amethyst that is ideas situations articles methods more knowledge points articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Tech Info vpn OPPO Reno NVidia