I'm trying to get the content of an article and display it using AJAX by replacing the content of a div with the new article's content. In order to do this I want to make an asynchronous jQuery call to a PHP page that simply outputs the article's body. However, this PHP function needs access to the Drupal PHP functions in order to operate properly. Where or how can I create a PHP file that will have access to these functions in a Drupal install?
migrated from stackoverflow.com Mar 1 '12 at 15:26This question came from our site for professional and enthusiast programmers. |
|||||
|
To get data from Drupal's database and/or produced in PHP, you need a page callback (in a custom module) that output the data without the full layout rendering. This is easily doable by printing the content of the page directly in your page callback instead of returning it. If you want to retrieve nodes in AJAX, you can also use the Services module which provides JavaScript callable endpoints (REST, JSON over HTTP) for nodes, users, taxonomy terms, etc. If you still want to work outside Drupal, in a standalone script, you should include Drupal's
|
||||
|
If you want to get another drupal article's body text, you need not write custom php code in file. You could do that using views may be in the following way:
Now you can call this view(using view page URL) with required parameter to get article body in JSON format. That can be used by your javascript to place the content inside div. |
|||
|