• Home
  • Get help
  • Ask a question
Last post 5 min ago
Posts last week 82
Average response time last week 34 min
All time posts 68066
All time tickets 10515
All time avg. posts per day 20

Helpdesk is open from Monday through Friday CET

Please create an (free) account to post any question in the support area.
Please check the development versions area. Look at the changelog, maybe your specific problem has been resolved already!
All tickets are private and they cannot be viewed by anyone. We have made public only a few tickets that we found helpful, after removing private information from them.

#1539 – error page and ajax

Posted in ‘sh404SEF’
This is a public ticket. Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.
Tuesday, 15 December 2015 12:55 UTC
bfgnet
 I am writing a module which submits a form using ajax (using com_ajax)

This works on every page except the error page - there are no php errors or javascript errors, it just does nothing when I press the submit button. I have looked at the source of the page and the module javascript and jquery are both loading on the page.

I have tested this with other templates - same result, but on a vanilla install of joomla without sh404SEF - this works because the modules js is not loaded so it does a normal form submit.

Have you any ideas?
 
Tuesday, 15 December 2015 15:24 UTC
wb_weeblr
Hi

And what type of error/ behavior do you have in your browser console? surely you can step through your javascript and see what happens when you click on that button?

Rgds
 
Tuesday, 15 December 2015 16:04 UTC
bfgnet
I have spent some time looking at this and see that every time I click the Submit button a 404 error message pops up in the console. I think that because a proper 404 error is generated by sh404SEF - and doesn't seem to be by Joomla, that this is causing the issue and the difference in how it works.
Now I need to find some way to work around this.
 
Wednesday, 16 December 2015 21:25 UTC
wb_weeblr
Hi

So you say the error is a 404? What's the URL you are requesting? exactly and in ull,, better put a part of your javascript here.


Rgds
 
Thursday, 17 December 2015 10:35 UTC
bfgnet
$js = <<<JS
jQuery(document).ready(function ($) {
$('.anythingwrong').click(function (e) {
if($('#action').value != '' && $('#error').value != '')
{
var request = {
'option' : 'com_ajax',
'module' : 'anythingwrong',
'format' : 'raw',
'formd' : $('#anythingwrong').serializeArray()
};
$.ajax({
type : 'POST',
data : request,
success: function (response) {
if(response){
$('#aw').html(response);
}
},
error: function (e){
{$jserror}
}
});
}
e.preventDefault();
});
});
JS;

Note that $jserror is an empty string unless I have debug turned on in the module.

Default is to use the page url since I have not specified this in the request var. I have tried adding various urls to the request but they all give me the same error.

My solution for now is to check the input and work out if I am on an sh404SEF error page and don't output the javascript if that is the case. Then the form sends another normal post request to the error page. This works, my database entry gets written but then the page is logged twice in 404 errors.

Regards,
Helen

I can send the entire module to you if you would like.
 
Thursday, 17 December 2015 15:27 UTC
wb_weeblr
Hi

Well you have to specify a URL! if you leave it empty, as you do, then jquery POST the data to the current URL. And that URL is a 404, so Joomla replies with a 404.

What people usually do is pass a root URL from PHP:

JFactory::getDocument()->addScripDeclaration(
'var myCustomLiveSite = "'. JURI::root(true).'";'
);


Then you can use that variable in your javascript to POST data to.

Rgds
 
Monday, 11 January 2016 15:54 UTC
bfgnet
Hi, sorry to take so long to get back to you, but Joomla update broke my site images! I have spent quite a while testing various urls for the ajax post request, and I have finally settled on letting the request find its own url to post to unless this is a sh404 error page in which case I specify the root url. Still not sure why when I explicitly set the url to be the same as the page url (using JUri::current() ) for normal pages it is not always reliable, but at least it is working now. Thanks for your help. Regards, Helen On 17/12/2015 16:27, Weeblr wrote: >
 
Monday, 11 January 2016 16:03 UTC
wb_weeblr
Hi

Still not sure why when I explicitly set the url to be the same as the page url (using JUri::current() ) for normal pages it is not always reliable
Maybe because JURI::current() may not always return the current, full URL; From recollection, it the URL has query vars (ie /some-path?var=12&id=13), current() doesn't include them.

All good anyway, Closing this ticket now, feel free to open a new one as needed. If you do so, please mention this ticket number in the new one.

If you created any superadmin account for us, be sure to delete or block it now to avoid unnecessary risk in the future.


Rgds
 
This ticket is closed, therefore read-only. You can no longer reply to it. If you need to provide more information, please open a new ticket and mention this ticket's number.