Help with jQuery string formatting
Why does the following:
$("a").sortable( {
update:function() {
var urls = "";
$.map($("a"), function(elt) {
urls += "url=" + elt.href + "&";
});
$.ajax( {
url: 'server_side_process_one.aspx',
type: 'POST',
data: { urls.substr(0,urls.length - 1) },
success: function() { alert(urls.substr(0,urls.length - 1)); }
});
}
});
return paths in the following format:
file:///C:/Program%2开发者_Python百科0Office/OFFICE11/WINWORD.EXE
but the following:
$("input:checkbox").live('change', function() {
var that = this;
$.ajax({
url: 'server_side_process_two.aspx',
type: 'POST',
data: { $(that).attr("id") },
success: function() { alert($(that).attr("id")); }
});
});
returns path in the following format:?
C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
Any idea how to get both functions to return in the same format? Preferably both should return in the basic format without all the extra characters, i.e.
C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
but not
file:///C:/Program%20Office/OFFICE11/WINWORD.EXE
When you asks for an element's href, you'll get a version of this attribute, processed and cleaned by the browser. So, it really depends on what your aspx script does, but be sure that the URL you're passing to you script through strURLs
is something with the appropiate URI, like file:///C:/Program%20Office/OFFICE11/WINWORD.EXE
, and not an incorrect and malformed URL like C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE
.
Don't forget that you can see what you're sending to your script using tools like FireBug in Firefox.
Good luck!
This may just "patch" your problem, but you might just let the upper C# function
return "file:///C:/Program%20Office/OFFICE11/WINWORD.EXE"... and then correct the formatting.
string sRtn = "file:///C:/Program%20Office/OFFICE11/WINWORD.EXE";
sRtn = sRtn.Replace("file:///", "");
sRtn = sRtn.Replace("/", "\");
sRtn = sRtn.Replace("%20", " ");
精彩评论