简体   繁体   English

使用Ajax读取呈现为html的php文件

[英]read php file rendered html using ajax

I am just trying to read the file content of a rendering HTML of URL 我只是想读取URL呈现HTML的文件内容

Here the code i am using , its always going in error section . 我在这里使用的代码始终在错误部分。

  $.ajax({
            type: 'POST',
            url: 'http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0',
            dataType: 'html',
            success: function(data) {
                alert('success');
            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert('error');
            }
        });

but in case i run the same url directly in browser , its show me html. 但是如果我直接在浏览器中运行相同的URL,它会显示html。

here is url 这是网址

Working DEMO 工作演示

You can use this in your head tag 您可以在头标签中使用它

<script src="https://rawgithub.com/IonicaBizau/jQuery-cross-domain-requests/master/js/jquery.xdomainajax.js">
</script> 

code

$.ajax({
    url: 'http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0', // Or your web page link
    type: 'GET',
    success: function(res) {
      var headline = res.responseText;
      $('body').append(headline);
    }
  });

Hope this helps, Thank you 希望对您有所帮助,谢谢

Try the below code: 试试下面的代码:

   $('document').ready(function() {

      $.getJSON('http://anyorigin.com/get?url=' + 
      encodeURIComponent('http://www.withholding32.com/api/wh32calc.php?userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0') + '&callback=?',

      function(data){
         $("#result").html(data.contents);

       });

});

Refer : http://jsfiddle.net/R7EPt/275/ 参考: http : //jsfiddle.net/R7EPt/275/

将您的请求类型更改为GET,所有参数均在URL中给出。

if you are using post method for the ajax than you can't pass argument with url and also add control origin to your php file. 如果您对ajax使用post方法,则无法使用url传递参数,并且还需要将控件原点添加到php文件中。

try this... 尝试这个...

AJAX code: AJAX代码:

$.ajax({
        type: 'POST',
        url: 'http://www.withholding32.com/api/wh32calc.php',
        dataType: 'html',
        async:false,
        data: 'userid=nick&fpp=12&ffs=Single&fa=0&fgp=6000&figp=0&fiytd=0&st=6&stp=6000&ss=Single&sa=0&sad=0&stca=0',
        success: function(data) {
                    alert('success');
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert('error');
        }
    });

PHP CODE: PHP代码:

header("Access-Control-Allow-Origin: *");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM