Convert site from PHP to HTML5/JS/ajax only make use of 404 page

subject : convert site from PHP to HTML5/JS/ajax only
A

http://www.yyyyy.com/HONDA-FIT-Saloon-15-I-from-2012-for-sale-in-yyyy-yyyy-AD-204755

basically a PHP car dealers site has links as this where last number in url car Id used to call a similar url underground like this 404.php called and in 404.php this exist…

http://www.yyyyyy.com/carDetails.php?n=1&car_id=$car_id

echo file_get_contents("http://www.yyyyy.com/carDetails.php?n=1&car_id=$car_id"); 

This is a good way… do this in PHP…? Converting to JS/Ajax withOut PHP … is it good and productive way?

You can’t replace all your PHP with Javascrpt. One is server-side scripts, the other is client side.

yes but if old site PHP and new ajax /js what to do? is a=easy implement same functionality?

If you’re referring to node.js it’s a complete rewrite.

If all your PHP script does is fetching and returning data from another server based on the current URL, this can indeed be done with JS.

var req = new XMLHttpRequest(),
    
    // Get the car ID from the current URL
    car_id = parseInt(window.location.href.match(/\d+$/));

// Listen to changes of the request's readyState
req.onreadystatechange = function() {

    // When the readyState is 'DONE'
    if (this.readyState === 4) {

        // Log the response
        console.log(this.responseText);
    }
};

// Actually open and send the request. The response will be handled
// asynchronously by the above function
req.open('GET', 'http://www.yyyyy.com/carDetails.php?n=1&car_id=' + car_id);
req.send();

PS: You can check if the page does exist with this.status === 404 in the onreadystate handler.

1 Like

only where cross domain access is permitted by the server AND where JavaScript is actually enabled. So not for everyone as it does with the server side version.

Most sites aren’t going to allow that. You will need some type of server side proxy hosted on your own domain.

1 Like

With PHP, you have control over the site’s functionality. If you rely on (front-end) JS to do all this, you have to hope that the end user has JS enabled, that JS doesn’t fail to load properly, etc. etc. What’s your rationale for switching to JS?

2 Likes

Old site was php details.php
New details.html but ajax loading

Tried get file contents on details.html but ajax Not load content

I will try use jQ load html ajax method. …

This you think should work eg load (“details.html? Carid=456789”

In other words two ajax s one load another inside details.html…well?
Or needed php pages?

Is it ajax load only for static content? I guest yes will not load inside html page ajax…

any hint any other way…

You’re not going to be able to load another sites content with Ajax. You need a server side proxy hosted on your own domain due to cross origin request policy restrictions.

Load from same site url
meant

is any pattern implement urls of ccccc.com/name-model-AD-678905
go to ccccc.com/details.html?678905

only the 404 trick can do this or???

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.