WebApp Development: Solving the cross-domain problem of AJAX requests

Source: Internet
Author: User

Service side: PHP

Client: Andorid, HTML5, JQuery, Ajax

Phenomenon: This would like to use jquery Ajax function from the server to retrieve the data stored in the phone's cache, the result is always wrong, and later thought may be a cross-domain problem, so check the next JSONP of the program first to run the process, tomorrow to improve to see what good plan

Service side: http://www.code-style.com/test/a.php

<? PHP // The service side returns JSON data $arr=array(' name ' = ' shujun.li '); $result=json_encode ($arr); // Dynamic Execution callback function $callback=$_get[' Callback ']; Echo $callback. " ($result) ";? >

Client

<!DOCTYPE HTML><HTML><Head>    <MetaCharSet= "Utf-8">    <title>Listview autodividersselector-jquery Mobile Demos</title>    <Scriptsrc= "Js/jquery.js"></Script>        <Scripttype= "Text/javascript">$.ajax ({URL:"http://www.code-style.com/test/a.php", DataType:'Jsonp', Data:"', Jsonp:'Callback', Success:function(Result) {alert (result["name"])}, timeout: the    });</Script></Head><Body></Body></HTML>

Generate url:http://www.code-style.com/test/a.php?callback=jquery1102004144126083701849_1420635061128&_= 1420635061129

Response: jquery1102004144126083701849_1420635061128 ({"Name": "Shujun.li"})

WebApp Development: Ajax requests resolution of cross-domain issues

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.