weixin_33695082 2012-06-15 14:02 采纳率: 0%
浏览 20

跨域JavaScript Ajax

I'm dealing with a problem the whole week already and can't find the answer anywhere.

This is the problem:

XMLHttpRequest cannot load http://www.websiteA.com/process.php. Origin http://clientwebsi.te is not allowed by Access-Control-Allow-Origin.

I have a Javascript file that is located at the server from website A. Clients can load the JS file on there website.

On the server A is also a process.php located that puts information in the database on server A.

I'm using now this code:

var dataText = 'page=' + top.location.host;
$.ajax({
    type: "POST",                 
    url: "process.php",         
    data: dataText,              
    error: function(request,error){
            alert(error);
        },
    success: function(request) {
        alert(request.length);
    }
});

This code works perfectly on localhost but not when i'm using the server A and client server (cross domain)

This is the online code:

$.ajax({
    type: "POST",                 
    url: "http://www.serverA.com/process.php",         
    dataType: "json",
    data: dataText,              
    error: function(request,error){
            alert(error);
        },
    success: function(request) {
        alert(request.length);
    }
});
  • 写回答

2条回答 默认 最新

  • local-host 2012-06-15 14:05
    关注
    $.ajax({
        type: "POST",                 
        url: "http://www.serverA.com/process.php",         
        dataType: "jsonp",
        data: data,  
        crossDomain: true,            
        error: function(request,error){
                alert(error);
            },
        success: function(request) {
            alert(request.length);
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题