This is for a small internal tool to enable a few people to query the database. The query has a plus sign as below:
SELECT SUBSTRING(DateName(month,CreatedOn),0,4) + ' - ' + SUBSTRING(CAST(Year(CreatedOn) AS varchar(10)),3,3) as Month, Year(CreatedOn) as Year,
The query is passed to the server using a jquery ajax call
var d = "query=" + $("#txtQuery").val();
$.ajax({
type: 'GET',
url: '/Reports/GetReport',
data: d,
However, I get a server error and debugging I find that the query on the server is missing the plus sign. i.e.
SELECT SUBSTRING(DateName(month,CreatedOn),0,4) ' - ' SUBSTRING(CAST(Year(CreatedOn) AS varchar(10)),3,3) as Month
And from FireBug,
localhost:1489/Reports/GetReport?query=SELECT%20SUBSTRING(DateName(month,CreatedOn),0,4)%20+%20%27%20-%20%27%20+%20SUBSTRING(CAST(Year(CreatedOn)%20AS%20varchar(10)),3,3)%20as%20Month,%20Year(CreatedOn)%20as%20Year..
How do I ensure that the plus is treated as a part of the input string and not as a concat operator which seems to be the case here.
“+” is treated as a space in URIs.
Use encodeURIComponent.