Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
HTML, Javascript, CSS, DHTML, XHTML
Aiuto su $Ajax
sabato 13 aprile 2013 - 18.39
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Elenco Tags
Javascript
86Marco
Profilo
| Expert
889
messaggi | Data Invio:
sab 13 apr 2013 - 18:39
Salve ragazzi volevo un vostro aiuto se possibile.
Mi sono da poco dedicato a Jquery facendo anche qualche buon progettino lavorando anche con $Post.
Mi sono addentrato su uno script, che vi allego, e vorrei delle delucidazioni da Voi.
Nel caso specifico su questo script non capisco alcune cose:
1) content-type a cosa serve? che valori può avere?
2) datatype a cosa serve? che valori può assumere?
3) Quando devo scrivere il risultato della funziona di callback con parametro msg, perché scrivo msg.d? Quella 'd' che sarebbe?
Spero di ricevere Vs .
grazue milleee
488x185
22Kb
0v3rCl0ck
Profilo
| Guru
1.120
messaggi | Data Invio:
dom 14 apr 2013 - 11:16
>Salve ragazzi volevo un vostro aiuto se possibile.
Ciao!
>
>Mi sono da poco dedicato a Jquery facendo anche qualche buon
>progettino lavorando anche con $Post.
>
>Mi sono addentrato su uno script, che vi allego, e vorrei delle
>delucidazioni da Voi.
>
>Nel caso specifico su questo script non capisco alcune cose:
>1) content-type a cosa serve? che valori può avere?
contentType (default: 'application/x-www-form-urlencoded; charset=UTF-8')
Type: String
When sending data to the server, use this content type. Default is "application/x-www-form-urlencoded; charset=UTF-8", which is fine for most cases. If you explicitly pass in a content-type to $.ajax(), then it'll always be sent to the server (even if no data is sent). If no charset is specified, data will be transmitted to the server using the server's default charset; you must decode this appropriately on the server side.
In poche parole il tipo di contenuto inviato al server.
>2) datatype a cosa serve? che valori può assumere?
dataType (default: Intelligent Guess (xml, json, script, or html))
Type: String
The type of data that you're expecting back from the server. If none is specified, jQuery will try to infer it 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:
"xml": Returns a XML document that can be processed via jQuery.
"html": Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.
"script": Evaluates the response as JavaScript and returns it as plain text. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true. Note: This will turn POSTs into GETs for remote-domain requests.
"json": Evaluates the response as JSON and returns a JavaScript object. The JSON data is parsed in a strict manner; any malformed JSON is rejected and a parse error is thrown. As of jQuery 1.9, an empty response is also rejected; the server should return a response of null or {} instead. (See json.org for more information on proper JSON formatting.)
"jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.
"text": A plain text string.
multiple, space-separated values: As of jQuery 1.5, jQuery can convert a dataType from what it received in the Content-Type header to what you require. For example, if you want a text response to be treated as XML, use "text xml" for the dataType. You can also make a JSONP request, have it received as text, and interpreted by jQuery as XML: "jsonp text xml." Similarly, a shorthand string such as "jsonp xml" will first attempt to convert from jsonp to xml, and, failing that, convert from jsonp to text, and then from text to xml.
In poche parole il tipo di dati restituiti dal server. Oltre a html, xml e text, accetta script (script JavaScript), json e jsonp (oggetti JavaScript da server locali e remoti).
>3) Quando devo scrivere il risultato della funziona di callback
>con parametro msg, perché scrivo msg.d? Quella 'd' che sarebbe?
nel tuo caso l'oggetto ritornato è di tipo json, e quindi può anche essere un class object, e facendo msg.d, vuoi accedere alla proprietà 'd' dell'oggetto ritornato dal server. Per esempio il server potrebbe ritornare un oggetto utente così composto:
IDUtente
Nome
Cognome
e quindi nella funzione di callback potresti leggere queste informazioni così:
msg.IDUtente
msg.Nome
msg.Cognome
>
>Spero di ricevere Vs .
>
>grazue milleee
>
di niente
EDIT: mi sono dimenticato di passarti il link completo alla reference di jQuery.ajax() quindi eccolo:
http://api.jquery.com/jQuery.ajax/
anche qualcosa in ita:
http://www.html.it/pag/18403/jquery-ajax/
-------------------------------------------------------
Michael Denny
Lead Software Developer & Solutions Architect
http://blogs.dotnethell.it/Regulator/
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !