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.
Related
I have the following ajax request:
var value = $.ajax({
type: "POST",
url: "url.php",
data: { $(someform).serialize(), something: test_number },
cache: false,
async: true
}).success(function(data){
alert("success!");
}).error(function() {
console.log("FAILED");
});
But it is logging FAILED although the url is right. What happens is that the page refreshes the page and the php query isn't done. I guess there are no errors within the url... any idea on why this happens?
You are kind of mixing methods to send your POST data. You can't serialize a query strong and then also append additional data to it using javascript object construct. You will likely need to manually append the last data element to the query string like this:
data: $(someform).serialize() + '&something=' + encodeURIComponent(test_number),
Of course there could still be a problem on the server-side script which is causing a non-200 HTTP response code (and triggering error handler). You just need to fix this first, and if you still have a problem, debug the server-side issue.
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.
I'm getting all ajax responses as XML only. When i implement them, it worked fine(i got the responses as HTML). Is there any reason that we are receiving the responses as XML by default? I think something has been changed recently. But i couldn't able to corner the change. Any help on this will be greatly appreciated.
NOTE: Please note that I'm using jQuery for AJAX.
Here is the code i'm using in one of the place in my site (in all the places i'm using in the same manner and it is coming in XML only, as shown in the screenshot)
$.ajax({
type: "POST",
url: "/ajax_contests_submissions_more&popup=yes",
dataType:"html",
data: 'last_pos='+queryPos,
cache: false,
error:function(XMLHttpRequest, textStatus, errorThrown) {
alert('sorry, we were unable to process your request. please try again later');
},
success: function(html)
{
}
});
Please check this image which shows that browser will not guess the XHTML as XML as per #dystroy's comment.
AJAX replies tries to parse the response as XML. So you can grab either XML or the raw text.
See this
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).
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);
}