[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
Is this the wrong forum for this question? Should I take it to the dev list or put it in the bug tracker? Thanks, -ben On Dec 4, 2:00 pm, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
Ben, (its like talking to myself) Put cache:true into your ajax call, the ? is to prevent caching. On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Is this the wrong forum for this question? Should I take it to the dev list or put it in the bug tracker? Thanks, -ben On Dec 4, 2:00 pm, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- Benjamin Sterling http://www.KenzoMedia.com http://www.KenzoHosting.com http://www.benjaminsterling.com
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
Sadly. That doesn't do it either. I am deliberately trying to send a ? (since the bug occurred when a user typed it into an input box that I use as the basis of an AJAX request). The bug occurs because jQuery is treating =? as a special string, but it can happen for mundane reasons, and there is no way to disable the behavior. -ben On Dec 6, 11:30 am, Benjamin Sterling [EMAIL PROTECTED] wrote: Ben, (its like talking to myself) Put cache:true into your ajax call, the ? is to prevent caching. On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Is this the wrong forum for this question? Should I take it to the dev list or put it in the bug tracker? Thanks, -ben On Dec 4, 2:00 pm, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- Benjamin Sterlinghttp://www.KenzoMedia.comhttp://www.KenzoHosting.comhttp://www.benjaminsterling.com
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
I am doing something encodeURIComponent(url) in a wordpress plugin, would that help? On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Sadly. That doesn't do it either. I am deliberately trying to send a ? (since the bug occurred when a user typed it into an input box that I use as the basis of an AJAX request). The bug occurs because jQuery is treating =? as a special string, but it can happen for mundane reasons, and there is no way to disable the behavior. -ben On Dec 6, 11:30 am, Benjamin Sterling [EMAIL PROTECTED] wrote: Ben, (its like talking to myself) Put cache:true into your ajax call, the ? is to prevent caching. On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Is this the wrong forum for this question? Should I take it to the dev list or put it in the bug tracker? Thanks, -ben On Dec 4, 2:00 pm, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- Benjamin Sterlinghttp://www.KenzoMedia.comhttp://www.KenzoHosting.comhttp://www.benjaminsterling.com -- Benjamin Sterling http://www.KenzoMedia.com http://www.KenzoHosting.com http://www.benjaminsterling.com
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
Sadly... no. If I were to do that then I would get double escaped data... The code that converts an object to a serialized form is already calling encodeURIComponent on the key names and the values... (see http://dev.jquery.com/browser/trunk/jquery/src/ajax.js line 454ish) -ben On Dec 6, 3:27 pm, Benjamin Sterling [EMAIL PROTECTED] wrote: I am doing something encodeURIComponent(url) in a wordpress plugin, would that help? On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Sadly. That doesn't do it either. I am deliberately trying to send a ? (since the bug occurred when a user typed it into an input box that I use as the basis of an AJAX request). The bug occurs because jQuery is treating =? as a special string, but it can happen for mundane reasons, and there is no way to disable the behavior. -ben On Dec 6, 11:30 am, Benjamin Sterling [EMAIL PROTECTED] wrote: Ben, (its like talking to myself) Put cache:true into your ajax call, the ? is to prevent caching. On 12/6/07, Ben Bennett [EMAIL PROTECTED] wrote: Is this the wrong forum for this question? Should I take it to the dev list or put it in the bug tracker? Thanks, -ben On Dec 4, 2:00 pm, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- Benjamin Sterlinghttp://www.KenzoMedia.comhttp://www.KenzoHosting.comhttp://www.benjam... -- Benjamin Sterlinghttp://www.KenzoMedia.comhttp://www.KenzoHosting.comhttp://www.benjaminsterling.com
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
? is a reserved character in URLs (it separates the domain from the GET parameters) and must be encoded if it's data. http://www.blooberry.com/indexdot/html/topics/urlencoding.htm Scott On Dec 4, 2007 2:00 PM, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- -- Scott Trudeau scott.trudeau AT gmail DOT com http://sstrudeau.com/ AIM: sodthestreets
[jQuery] Re: Data containing ? at the start getting converted to jsonp.... by ajax() call
Thanks for thinking about this. However the items in the data object are being escaped automatically for me (since I have not set the processData option to false). So if I escape it, then it is double escaped on the wire. Note that if the ? does not appear at the start of the string then it is correctly escaped and transmitted across the wire. Also, the regular expression being used to find the strings to change looks for both =? and =%3F (the escaped form). This behavior is present in the latest svn version of the code too: http://dev.jquery.com/browser/trunk/jquery/src/ajax.js -ben On Dec 4, 2:43 pm, Scott Trudeau [EMAIL PROTECTED] wrote: ? is a reserved character in URLs (it separates the domain from the GET parameters) and must be encoded if it's data. http://www.blooberry.com/indexdot/html/topics/urlencoding.htm Scott On Dec 4, 2007 2:00 PM, Ben Bennett [EMAIL PROTECTED] wrote: This is my first post so I really should thank everyone for a fanatastic library. However, I think I have found a bug... Using jQuery 1.2.1, if I have: $.ajax({ type: POST, url: test.html, dataType: json, data: {query: queryString}, }); When queryString starts with a ? it will get converted to jsonp1231234124... This is clearly happening because of the code at line 2226 of the full release version: // Build temporary JSONP function if ( s.dataType == json (s.data s.data.match(jsre) || s.url.match(jsre)) ) { jsonp = jsonp + jsc++; // Replace the =? sequence both in the query string and the data if ( s.data ) s.data = s.data.replace(jsre, = + jsonp); s.url = s.url.replace(jsre, = + jsonp); ... But I see no way to prevent that from happening. Now... one might suggest that I should avoid a leading ? in my option names. But I am taking them from input boxes and ? is a valid thing for a user to type. Unfortunately there seems to be no good way to escape the string to prevent this behavior (without teaching the called code how to unescape it). Also, the docs don't mention that the =? escaping happens to a json dataType... I see it for jsonp. Is this behavior intentional? If so, there should be a way to suppress it or at a way for the calling code to escape the values to cause a leading ? to be passed to the server. -ben -- -- Scott Trudeau scott.trudeau AT gmail DOT comhttp://sstrudeau.com/ AIM: sodthestreets