« first day (20 days earlier)      last day (4933 days later) » 

11:03 PM
@NickCraver:
data is null
[Break on this error] if(typeof stuff == "object") { alert(data.error); }
 
what's stuff?
whatever the parameter is in your callback, use that
if it's function(stuff) then use stuff.error
 
Ok
dataType: 'json',
success: function(stuff){
if(typeof stuff == "object") { alert(stuff.error); }
Still getting "stuff is null"
 
for non-error requests?
oh take that dataType off there, I asked you this earlier :)
 
ok
 
45 mins ago, by Johnson
it should determine of the headers coming back
 
11:10 PM
Now i have no datatype
 
now it shouldn't be null for non-errors, it'll be a string
and basically shouldn't fail
 
Ok now i dont get any errors
/no fail, but im not receiving the error i made
 
what's the response coming back?
 
json_encode(array('error' => 'blabla'));
 
make sure that json your echoing is the only thing your outputting, or it's not valid JSON
e.g. make sure it's not returning the rest of your page as well, look in the net tab if you're using firebug to see
 
11:11 PM
ok
 
you should only be seeing: { "error": "blabla" }
gotta go, dinner time, good luck!
 
Its empty
the response
Ok fixed.
Now i am only seeing { "error": "blabla" } , but it doesnt give me the alert
I'm almost there damnit
 
I don't think it will give an alert on json data
I stand corrected, it will alert an object
@Johnson show me the code for "Success" for the ajax object
 
success: function(stuff){
if(typeof stuff == "object") {
alert(stuff.error);
}
else { /* do stuff, data is an html string */

$(stuff).prependTo('#PrivateMessages').fadeIn(1000);
$('#txt').val("");

$("#pmResponse").text("Skickat!").show().fadeOut(4500);
$('#sendPM_btn').attr('disabled', false);
$('#txt').attr('readonly', false);
$('#title').attr('readonly', false);
}
}
It doesnt run the stuff.. else{
 
it doesn't run the "else" or it doesn't show the alert?
 
11:23 PM
It doesnt run the else AND it doesnt show the alert
 
change the alert to alert('hi'); and see if it shows the alert
 
It doesnt show hi alert neither..
But when i move the alert('hi') right under success: function(stuff){ , it alerts..
 
yes
I can only think that you have a typo, but if you copy-pasted to show me
 
i have copy pasted
above^
 
11:28 PM
I tried to alert(stuff.error); right under success: function(stuff){ it alerts "undefined" ??
{"error":"blabla"} is what i am getting in the response, so its valid JSON there..
.......and now it works
I made: dataType: 'json', in the $.ajax
 
ok, yay for you
 
and it alerted just fine
but why did nickcraver tell me to remove it?
:84549
 
tell you to remove what?
 
"oh take that dataType off there, I asked you this earlier :)"
how can i repost his comment
on here ?
 
on the arrow, permalink
 
11:33 PM
23 mins ago, by Nick Craver
oh take that dataType off there, I asked you this earlier :)
 
what datatype are you getting back?
list me only one datatype and be exact
for sure, always, what datatype are you getting back on this request
@Johnson ... are you there?
 
@drachenstern im here..
how can i see what datatype im getting back?
 
Can you answer the question?
no no no
 
No i cant, nervous to answer wrong
 
you are the developer, you are designing the system
you must know what the return datatype is
it doesn't imagine one for you, you determine it
so what datatype are you returning?
 
11:35 PM
json ?
For what????+
tell me for what
 
And now you see the problem
this is why I said to use only HTML
You are returning TWO datatypes from the server
one for error, and one for valid
 
yes
 
The dataType option is for when only one is expected, so that the system can reject bad data
 
Nickcraver said i could do that
...
 
in your case, you can't KNOW what type you will get back, so you can't define it
if you reject JSON then the error will be silent
if you reject HTML then the command will not work
 
11:37 PM
what do i do?
 
if you had READ the api for api.jquery.com/jQuery.ajax then you would know this
you leave that field empty.
with apologies to those on the feed, the next post is long:
dataTypeString
Default: Intelligent Guess (xml, json, script, or html)
The type of data that you're expecting back from the server. If none is specified, jQuery will intelligently try to get the results, based on the MIME type of the response (an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string). The available types (and the result passed as the first argument to your success callback) are:
 
ohh
 
so if you don't change specify a dataType and you just leave it alone, then the system will decide for you if it is JSON or HTML or XML or whatever
 
I made a restriction
 
and, magically, all the time that the developers spent writing API documentation suddenly has a purpose.
 
11:39 PM
And my html wont work now
If i leave it alone, it doesnt detect the json
 
it should
it may detect it as a string tho, I would have to see what you're getting in Firebug to know for sure
 
the response?
 
in the response tab, yes
 
ok i have removed the datatype, running the call:
{"error":"You have an error"}
copy pasted from the response tab
 
click that link
if you really are getting that back as json, then this is what you should see
 
11:43 PM
I see this when i specify dataType to json as you know..
hmm
 
What could be wrong?! I dont have a space before or after or anything
But here's what Is strange: It doesnt run neither the }else OR the alert
 
how do you know it doesn't run the else?
you're not giving it good data
 
because
$('#sendPM_btn').attr('disabled', false);
would run
and it doesnt activate the button
which it should if it ran }else
 
I need to brb
my apologies
b
 
11:50 PM
ok
this one is difficult huh :P
 
in the net tab, on the Headers for the error response
I had to get my copy spun up so I could play with it for a second
are you following? do you have firebug open?
Response Headers
Date Fri, 05 Nov 2010 23:50:40 GMT
Server xxx
Cache-Control private, max-age=0
Content-Type application/json; charset=utf-8
Content-Length zzz
show me that from the net tab?
 
ok
 
1 hour ago, by Nick Craver
If you're returning an error: header('Content-type: application/json');
 
second
Response Headers
Date Fri, 05 Nov 2010 23:41:02 GMT
Server Apache
X-Powered-By PHP/5.3.3
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Connection close
Transfer-Encoding chunked
Content-Type text/html
What did he mean with that drachenstern?
 
now look at @NickCraver's comment that I copied
compare MY Content-Type and YOUR Content-Type
see anything?
 
11:54 PM
Yes
text/html
Should make the header in the php file? But you said that i shouldnt specify? Will it then also show HTML right?
 
the dataType in the ajax object I said you shouldn't worry about
I never said the PHP
 
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Just changed it, and it works
Damn you are smart..
 
did you set it to what @NickCraver gave you to set it to?
or did you invent some new setting?
 
Yes, that's what i did then it started working
 
11:57 PM
I feel like im dumb
 
Well, you're definitely trying to work faster than you're listening
 
Nickcraver explains everything, and i dont understand anything. first after
Yeah, could be that..
Got a question for that header i just set. Will it still show my HTML normal? on the }else
 
so I can't answer that without seeing your PHP
I presume the php looks like this:
 

« first day (20 days earlier)      last day (4933 days later) »