最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ajax URL POST accept Localhost and IP - Stack Overflow

programmeradmin2浏览0评论

Im doing an ajax post but I have a problem.

I want to post to an url but I want to accept in the explorer, "localhost" and the "IP address".

If I put like this:

 $.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]);
                });
           }
       }); 

Only accept me typing the url, its possible to do it with the url and localhost too?

Thank You in advance!

Im doing an ajax post but I have a problem.

I want to post to an url but I want to accept in the explorer, "localhost" and the "IP address".

If I put like this:

 $.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]);
                });
           }
       }); 

Only accept me typing the url, its possible to do it with the url and localhost too?

Thank You in advance!

Share Improve this question edited Apr 28, 2014 at 9:18 Funereal asked Apr 28, 2014 at 9:09 FunerealFunereal 6732 gold badges12 silver badges34 bronze badges 4
  • Can you show us some actual code you're working with? As it is right now, the question is a little vague. – Cerbrus Commented Apr 28, 2014 at 9:16
  • @Cerbrus Updated. When I type in browser "localhost/test/suma.php" dont work the POST, only with the IP. – Funereal Commented Apr 28, 2014 at 9:19
  • just use the /test/suma.php part as url: url: '/test/suma.php' – devqon Commented Apr 28, 2014 at 9:37
  • @user3153169 Is not possible to do it with keeping the ip address and when I put in the browser localhost, accept as crossdomain? – Funereal Commented Apr 28, 2014 at 9:44
Add a ment  | 

2 Answers 2

Reset to default 2

Just remove the whole domain part, only use the relative path:

$.ajax({

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

I you are working in the same domain, use relative path.

If not, you need enable 'crossDomain' option.

发布评论

评论列表(0)

  1. 暂无评论