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.
Related
I use:
wampserver
laravel 5
bootstrap v3.3.6
I'm new in laravel, I usually use a manual route::get. Now I try to use route:resource to make things faster but somehow those two display different result even though it's should be showing the same page.
My routes code:
Route::get('create', 'PostController#create');
Route::resource('posts','PostController');
as you can see above, it's directing to the same controller
PostController#create code:
public function create()
{
$data['title'] = ' | Create Post';
return view('posts.create',$data);
}
When I go to blog.dev/create (which is from route::get). It's successfully displaying:
BUT, when I go to blog.dev/posts/create (which is from route::resource). It's showing a css-less page:
Why is that happen? any way to fix it? (I prefer not to use route::get)
Note:
I've tried different browsers, clear cookies&cache and restarting wamp
Both have exactly the same code in view page source from browser.
It seems to be issue with css file paths. Your css paths are relative.
make your css file path to be absolute.
Read this:-
https://css-tricks.com/quick-reminder-about-file-paths/
https://www.w3.org/TR/REC-CSS1/#url
http://jeffreybarke.net/2013/06/paths-and-urls-relative-and-absolute/
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 want a piece of code on the index of my Code Igniter's script so I can change the identety or name of my controller from agent69 to agent007_and_supergirl,and also a way to beat any rule that pages might have against using underscore to separate words as an amendment.
In other words I want that all the calls that the processor of my server has inside my code igniter for agent69 be translated to calls to agent007_and_supergirl
Is just a change of identety for the controller without altering the main controler's functionality and without getting my hands dirty with coding.
If you want re route your default controller url, you have to edit routing configuration like this:
in application/config/route.php
$route['agent007_and_supergirl'] = 'agent69';
Now agent69 Controller will be accessible by http://youriste.com/agent69 and http://yoursite.com/agent007_and_supergirl as well
CodeIgniter URI Routing Guide
Working on config/routes.php yelded miserabe results on past,remember that is an identity matter
And I want all the calls of agent69 be sent to agent007_and_supergirl that is its new identity
What was successfull on the past about this mattar was controller and file cloning,it worked masterfully
but this only intercepted few server calls so for me to get all the server calls, I need to clone every
single fie on the script so I feel silly teling you again thats why I didnt want to get my hands dirty with code
because is plenty of code.
Well hope that you can help me master this code that goes on the index of my code igniter script--///The code cant appear here so its below in the comment to lighta thanks 4 readin
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';
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 :-)