Use AJAX without writing a module - D7 I want to use ajax to load some html from a php file. I don't want to write a module. So, here's the thing I did:

In sites/all/themes/mytheme/js/myjs.js:

$('#color_main_id a').click(function() {
  $.ajax({
    url: "get_node_details.php",
    type: 'GET',
    cache: false,
    // data: nid &lt;--- Question#1
    data:  "color=" + this.rel,
    success: function(data, status, jqXhr) {
      $('.product-summary').html(data);
    }
  });
});


In sites/all/themes/mytheme/js/get_node_details.php I wrote some code to get a node detail with entity_load and field_view_field.

Here's the questions:


How can I pass the current node id from my js function in js file to php function in php file? (See the comment above)
In get_node_details.php I've got Call to undefined function entity_load(). How can I solved this?


Thanks
I'm sorry to say but, you are doing it wrong.

In some very few cases it could be worth not to write a module for an ajax request. The reason would be that you want to do something simple, not related to Drupal that needs to be very fast. I did this once for a site where I needed to look up if a domain name was registered or not.

In this case you are not isolated from Drupal. You need to know the context of your script (The node id) and you need to use the Drupal API's entity_load, so instead  of creating a custom PHP file and writing code in there, why not create a module which is a PHP file, only it's named foo.module, use the drupal API's to in make the ajax callback hook_menu, and add the javascript with context drupal_add_js and you will save yourself a lot of work, by doing things the Drupal way. Drupal is made it make it easy to develop stuff by creating modules, instead of adding custom PHP files, which makes things a lot more difficult to manage.

If you really wanted to do this without creating a module, you would need to bootstrap Drupal in your custom PHP file (making it pointless to use a custom php file), and add the node id in the preprocess_node hook in your theme.