Ajax With Get Method

javascript Code

<script>
      $.ajax({
            url: 'https://www.example.com/get_data/'+id,
            type: 'GET',
            dataType: 'JSON',
            success: function (data)
            {
                if(data.url)
                {
                    window.location.href = url;
                }
                else
                {
                    window.location.reload();
                }
            }
        });
</script>

Php Code

function get_data($id)
{
   $data['id'] = $id;
   $data['url'] = 'http://www.postsparrow.com/';
   echo json_encode($data);
}

1 Comments

Test Comments

Leave a Reply

You must be logged in to post a comment.