Opencart multisite registration strange request - php

I am having a problem that is really stumping me. In my Opencart installation my account registration page isn't working. It is a multisite and the page works fine on the other site. The problem is with the zones, when it tries to get zones based on the country it throws an error. When I examined it with Firebug I see that it sends an OPTIONS request instead of a GET request like it does when generating a successful request on the other page. Unfortunately this isn't the only problem, I was able to get it to send a GET request by specifying "crossDomain: 'false'" as an argument in the .ajax call and that still doesn't fix the error. The cookies being sent and returned are also different. I'm trying to find the underlying problem or at least something that will fix the issue.
Edit:
I added responded to questions in a comment as it Stackoverflow did allow me any more links.
2nd Edit:
I've found that the way you access the registration page matters. Some links to it don't generate any problems. I'm thinking more and more that this probably has something to do with cookies.

The OPTIONS request is indeed very strange in this case and almost looks like the client side (JS/browser) do not know what request methods could be used on the server.
Anyway, in the template catalog/view/theme/<YOUR_THEME>/template/account/register.tpl find this piece of code (almost end of file):
<script type="text/javascript">
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
dataType: 'json',
beforeSend: function() {
and before dataType: 'json', add type: 'get', or type: 'post', so You should end up with:
<script type="text/javascript">
$('select[name=\'country_id\']').bind('change', function() {
$.ajax({
url: 'index.php?route=account/register/country&country_id=' + this.value,
type: 'post',
dataType: 'json',
beforeSend: function() {
By this You specify which concrete HTTP request method should be used.

Related

numbers behind the ajax long polling url /controller/method?_xxxx

I'm using codeigniter, I am curious about the get query for long polling I made
function check_new_notif(){
$.ajax({
type:"GET",
url:"/MAIN/AJAX/new_unotif",
async:true,
cache:false,
datatype: "text",
timeout:20000,
success: function(dat){
show_new_notif(dat);
fetch_new_notif();
setTimeout(
check_new_notif,10000
);
},
error: function(XMLHttpRequest,textstatus,errorThrown){
show_new_notif("error");
setTimeout(
check_new_notif,10000
);
}
});
what is the number used for?
when my long polling request on server the links in firebug was like this
GET /MAIN/Ajax/notification?_=1466062273034
and the next call its /MAIN/Ajax/notification?_=1466062273035 ,incremented by one
Anyone know what this ?_=1466062273035 query means?
Thankies
When you set cache: false, it will append timestamp to your URL
Doc: http://api.jquery.com/jquery.ajax/
If set to false, it will force requested pages not to be cached by the
browser. Note: Setting cache to false will only work correctly with
HEAD and GET requests. It works by appending "_={timestamp}" to the
GET parameters. The parameter is not needed for other types of
requests, except in IE8 when a POST is made to a URL that has already
been requested by a GET.

jQuery ajax POST treated as GET with Laravel on the server

I'm having a bizarre issue where my POST request is being treated as a GET - this only happens on the LIVE environment and works fine locally. I have the correct POST route set up in laravel.
Would there be a case where jQuery would default to GET on a server environment - I'm currently accessing the site via an IP rather than the domain while the DNS resolves, could this perhaps cause an issue?
Route::post('/ajax/sale/filter', 'SalesController#ajaxFilterOptions');
$.ajax({ url: '/ajax/sale/filter/',
data: {filter: options, sale_id: window.saleId, outlet_type: outletType},
type: 'POST',
cache: false,
dataType: 'JSON',
success: _.bind(function (data) {
console.log(data)
}, this)
});
Your code lines up fine, you may want to check your htaccess file to see if a rewrite is happening (or corresponding rewrite with another httpd), or switch to $.post instead of $.ajax to make sure/force it as a POST request.
I know there is an accepted answer here. But whoever comes this page might be interested in knowing that if you remove the leading slash this will work fine. So in the example given, use url "/ajax/sale/filter" instead of "/ajax/sale/filter/"

On JQuery AJAX POST...request failed: URI too long (longer than 8190)

I got the error:
request failed: URI too long (longer than 8190)
I've seen other posts on StackOverflow for this one. Those posts recommend:
Not changing Apache settings (agree)
Using post, not get
Not using jsonp with post
I'm using jQuery's AJAX to POST:
$.ajax({
url: "test.php",
dataType: "json",
data: paras,
type: "POST",
success: function(ret){callback(ret);}
});
It's my impression you can use json just not jsonp. Correct? If so, why might I still be getting the error?
You should try setting proccessData to false.
From the docs:
By default, data passed in to the data option as an object
(technically, anything other than a string) will be processed and
transformed into a query string, fitting to the default content-type
"application/x-www-form-urlencoded". If you want to send a
DOMDocument, or other non-processed data, set this option to false.
so to prevent the data being added to the url:
$.ajax({
url: "test.php",
dataType: "application/json",
data: paras,
type: "POST",
proccessData: false, // this is true by default
success: function(ret){callback(ret);}
});
Honestly, I thought this was automatic, but since your url is too long it's worth a shot.
I ran into this issue when using jQuery to submit large forms, and was able to solve it by adding this plugin.
For example, using the following code to submit the form after adding the plugin resolved the issue for me:
$(formSelectorHere).ajaxSubmit({
url: myURL,
type: 'post',
contentType: "multipart/form-data",
data: $(this).serialize(),
success: function(data) {
function(data) {
//success code here//
}
});
If you're not using this to submit a form, this may not be relevant to you and won't solve your problem, but that's the most common situation where this issue appears, so I figured it was worth mentioning. (The plugin should also be able to submit a form using JSON, but haven't personally tested it).

Jquery ajax error - Requests adding GET var

My ajax function has stopped working all of a sudden.
function get_file_info()
{
$.ajax({
type: "GET",
url: "http://localhost/includes/get_file_info.php",
dataType: "json",
jsonp: false,
jsonpCallback: "callbackName",
success: function(data) {
return data;
}
});
}
I did some debugging and found that the ajax request is going to
http://localhost/includes/get_file_info.php?_=1297356964250
I am just would like to know what it is and can be used for, also how to remove so the ajax request is like below so it works again.
http://localhost/includes/get_file_info.php
Many Thanks
If you add:
cache: true,
to your call it will remove the timestamp which is there to always call a different URL's so the browser doesn't cache the result. This is standard for calls except for datatypes script and jsonp.
As others have stated though, it would be good to change the server side to stop turning away anything with GET's, maybe check if the get is a _ and only numeric, if not then turn it away...
The "_=1297356964250" query string is jQuery's method of preventing the URL being cached and returning an old result. Adding this ensures that you're retrieving a new response every time.
This is not the cause of your request breaking down. It must be from another issue. Have you tried logging your response and seeing what it returns?
success: function(data) {
console.log(data);
}

Jquery ajax request not working in IE?

I'm experiencing a strange problem in IE with an ajax request. It works fine in FF and Chrome, but for some reason no data is added to the resultsPage, slideInResults is called, and the empty page appears. Inspecting it I can see there is nothing there. What can I do to fix this?
$.ajax({
type: "GET",
url: "library/ajax/search.php",
data: dataString,
cache: false,
dataType: "html",
success: function(html){
$('#resultsPage').html(html);
slideInResults();
}
});
Check all tag and case of variables. They creates problem in IE if not properly close or in different case.
Use Fiddler to verify if the request is being sent. If it is, verify that the values sent are correct and finally, verify that the PHP page is not returning a bad response.
Report the response of the PHP page by using an Alert. This will assist with you identifying the source of the issue.

Categories