0

I am just trying to read the file content of a rendering HTML of URL

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.

here is url

2
  • Change type to GET? Commented Oct 31, 2013 at 9:59
  • This is because you have Cross-Origin issue. If you check your errorThown, you will see: is not allowed by Access-Control-Allow-Origin. Commented Oct 31, 2013 at 10:00

4 Answers 4

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

I don't have control over php page .
@rahularyansharma I have updated with code and demo, Check it and respond.
1

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/

Comments

0

Change your request type to GET, all your parameters are given in the URL.

Comments

0

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.

try this...

AJAX code:

$.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:

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

3 Comments

still error . i tried with both POST and GET . Is it possible for you to create js fiddle for your answer.
Can you add header("Access-Control-Allow-Origin: *"); into "withholding32.com/api/wh32calc.php" than only my jsfiddle link will work
I don't have control over that Page . that page is basically a provider of API >

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.