I have an ajax.php file in my Wordpress themes folder, and this was working fine on the DEV server. However, when I moved it to another server, the script that I have written no longer works... bizarre!
Im now rolling back to try and find the problem, but its most annoying because the very same version works on another server?!
Here's the code (for what its worth...)
Javascript Call:
function change_event(ID){
//alert("ID: "+ID);
$.post('wp-content/themes/muni/ajaxcalls.php',
{ id: ID },
function(data){
alert('complete: '+data);
//$('#showingevent').html(data);
});
}
ajaxcalls.php
require_once("../../../wp-blog-header.php");
global $more;
At this point, it breaks. There is no point including the code I have written after the require. If I comment this line, the code below works.
If I browse directly to the ajaxcalls.php file, I get the results I am expecting, but it will not feed back to the success function of the ajax call.
Any help would be greatly appreciated
Cheers SO!
Tom
edit: I'm firing change_event using this:
$('.eventoption A').click(function(ev){
ev.preventDefault();
change_event($(this).attr('id'));
clearInterval(timer);
});
I've also updated the change_event() function to reflect the one that I'm using rather than the debug that I was using before.
The problem happens as soon as I include the wp-blog-header.php file.
The trick was to include wp-load.php instead of wp-blog-header.php
use this. It is working on localhost, and i hope it will also work for live server.
First get the folder name of the root directory of your site
$folder = substr(substr($_SERVER["REQUEST_URI"],1), 0,
strpos(substr($_SERVER["REQUEST_URI"],1), "/"));
And then you can get the url for ajax using $_SERVER["DOCUMENT_ROOT"], $folder and wp-blog-header.php like this:
$ajax_url = realpath($_SERVER["DOCUMENT_ROOT"]).'/'.$folder.'/wp-blog-header.php';
Related
I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here's a screen:
![500 Internal][1]
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
[>>> Link <<<][2] (just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
I checked out the website.
I think Wordpress doesn't let you call .php inside of it's system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it's enough to have wp-admin/admin.ajax.php or something like this, i don't really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the "action" parameter is the function name which you want to call. And you need to put the PHP code into your current theme's function.php.
I have a bit of an annoying problem in Zend Framework 2. My js, which is located in my public/js folder, calls an action in the controller for my admin module. This is the call:
$.post('admin/expand', {
id: CCID
},function(data){
if(data.hasOwnProperty('info')){
expand(data.info);
} else {
console.log('Can\'t find customer info.');
}
},'json');
The call works fine normally, but then sometimes it won't be able to find the action. The console will say:
POST http://localhost/admin/admin/expand 404 (Not Found)
So I'll change the path in the AJAX to just 'expand' instead of 'admin/expand' and it'll work for a while... and then it won't until I change it back!
So it seems that sometimes it gets confused about the routing and sometimes it doesn't. Is this a namespace problem? The js file is supposed to be in my root/public/js, right? Does anyone know what the problem is here?
Try changing the url from admin/expand to /admin/expand . It is more pragmatic to use ZF2 routes.
Am I the only one having issues with the this?? I haven't got the exact code with me right now but it is something like the following... (this is the simplest of examples I am using to get up and running with TideSDK)
I have in my index.html...
<script>
Titanium.include("testLibrary.php")
</script>
<script>
var testresult = new testMethod();
document.write(testresult);
</script>
And the testLibrary.php file that I have in my resources directory is as simple as...
<?php
function testMethod()
{
$fixedResult = "The most basic php variable for display in the DOM";
return $fixedResult;
}
I have php switched on for packaging etc. It all worked fine when I included the php code within the index file so I know php is working, I just can't get include to work??
Moving my comments to an answer, since not sure WikingFrog got notified via email re: comments
why are you calling new on the method? var testresult = testMethod(); should work
also, you don't need <?php open tag in .php files which maybe the source of your issue.
This is how I call the editor:
new nicEditor({
buttonList : ['bold','italic','underline','upload'],
iconsPath:'img/nicedit.png',
uploadURI : 'http://server.com/integracion/files/nicUpload.php'
}).panelInstance(textareaId);
And the .php file exists ( and I the one in the Docs, and I updated the target paths )
/* I want them here http://server.com/integracion/files/uploads/ so... */
define('NICUPLOAD_PATH', './uploads'); // Set the path (relative or absolute) to
// the directory to save image files
define('NICUPLOAD_URI', '/uploads'); // Set the URL (relative or absolute) to
// the directory defined above
But I on response when upload completes (and of corse an alert from nicedit..)
<script>
try {
top.nicUploadButton.statusCb({"error":"Invalid Upload ID"});
} catch(e) { alert(e.message); }
</script>
what am I missing?
-EDIT
I think the problem might be in the php file:
$id = $_POST['APC_UPLOAD_PROGRESS']; /* APC is installed and enabled */
if(empty($id)) {
$id = $_GET['id'];
}
FINAL EDIT:
I have managed to make this work!
Here is an working example:
http://simplestudio.rs/yard/nicedit/
Uploaded images are going to be stored here:
http://simplestudio.rs/yard/nicedit/images/
And here is the whole code, just unpack it and put on your server, mainly I needed to adjust nicEdit.js because it had some issues.
http://simplestudio.rs/yard/nicedit/nicedit.rar
Just make your code with that js file and by looking at my example, it will work :)
Also you need to have php APC installed so that this script can work:
http://php.net/manual/en/apc.installation.php
If you by any mean have some problems I am here to solve it.
I will not delete this example on my server so that everybody who have this issue can freely download it...
The code responsible for image upload is the method uploadFile, it is looking for uploadURI option parameter.
You will need to modify onUploaded event handler to parse your custom response instead of the imgur's one (sample). By default it expects at least {"upload": { "links": {"original": "http://..."}, "image": {"width": "123" } }}.
I'm sorry but I can't help with the FormData() handling server side with PHP.
For more information you can try out the demo page on the nicEdit web site using Firebug or WebInspector to snoop the network requests, and, of course, the source code.
This question is somewhat related to my previous question (not necessary to go through it)
link text
, although this one is more of an Ajax problem.
I tested my page in firebug and I am getting the following error
Event.Observe is not a function
Event.observe('form908983160', 'submit', function(event) { new Ajax.Updater('comments','/blog/posts/comments/add', {asynchronous:true, evalScripts:true, parameters:Form.serialize('form908983160'), requestHeaders:['X-Update', 'comments']}) }, false);
I am using the prototype framework for developing my cake php application.
How should I fix this problem?
Guys, I really need your help in this one. I am really stuck at this one. [:(]
prototype.js has to be :
loaded in the page (verify it's not in 404, for instance)
loaded in the page before the execution of your script
Which generally means you need to include prototype.js first, and, only after that, you can include your scripts.
As a sidenote : you are not using any other JS Framework in that page, of course...
Remember that any Event.observers need to be used in global
Event.observe(window,'loaded',f);
// or
Event.observe(document,'dom:loaded',f)
otherwise they will not work.
For me it looks like there's problem with linking to Prototype. Open firebug and try to see the contents of your script files - if you see html, that means something went terribly wrong :-)