Ajax URL POST接受Localhost和IP

时间:2014-04-28 09:09:38

标签: javascript jquery ajax localhost

我正在做一个ajax帖子,但我遇到了问题。

我想发布到网址,但我想在资源管理器中接受," localhost"和#34; IP地址"。

如果我这样说:

 $.ajax({

           url: 'http://192.168.9.30/test/suma.php',
           type: 'post',
           data: {rows:rowValues, columns:columnValues},
           dataType: 'json',
           success: function(data){
               var rows = data.rows,
                columns = data.columns;

                // Insertar lo calculado  
                $("td.total").each(function(rowIndex){
                    $(this).text(rows[rowIndex+1]);
                });

                $("tr.totalCol td").each(function(columnIndex){
                    $(this).text(columns[columnIndex+1]);
                });
           }
       }); 

只接受我输入网址,可以使用网址和本地主机进行操作吗?

提前谢谢你!

2 个答案:

答案 0 :(得分:1)

只需删除整个域部分,只使用相对路径:

$.ajax({

    url: '/test/suma.php',
    type: 'post',
    // other stuff
});

答案 1 :(得分:1)

我在同一个域工作,使用相对路径。

如果没有,则需要启用“crossDomain”选项。