0

We have an ios application built with trigger.io. this application is using forge.request.ajax to send data to our servers. one of our requests occasionally throws an error and returns this:

{"message":"Invalid parameter not satisfying: url","type":"UNEXPECTED_FAILURE"}

since the input parameters are sent in json format I suspected that some characters inputted by users, could break the structure and cause this error. my code looks like this:

    forge.request.ajax({
        url: "someurl.php",
        dataType: "json",
        data:"some=data&and=some&more=data&which=is inputted by user",
        success: function (data) {

        },
        error: function (error) {
            forge.request.ajax({
                url: "errorlog.php",
                dataType: "json",
                data:"data=" + encodeURIComponent(JSON.stringify(error)),
                success: function (data) {

                },
                error: function (error) {
                }
            });                     
        }
    }); 

this code gives the above error half the time. and work on the other half. are there any limitations for input parameters in ajax request? since i can't edit objective-c code, i need a solution - preferably a filter- which ensures this function to work with whatever input is entered.

Volkan Ulukut
  • 4,230
  • 1
  • 20
  • 38

1 Answers1

1

Using encodeURIComponent may help:

var data = "some=data&and=some&more=data&which=is inputted by user"; 
forge.request.ajax({
    url: "someurl.php",
    dataType: "json",
    data: encodeURIComponent(data)
    ...

Passing request data as URL Parameters has more than it's share of gotchas though so it may also be worth taking a look at this StackOverflow question: When are you supposed to use escape instead of encodeURI / encodeURIComponent?

Community
  • 1
  • 1
  • now that I looked closer and realized that one of the newly added parameters was not actually filtered with encodeURIComponent, and the failed requests all had multibyte characters in that specific field which is not filtered. probably that is the case, thanks for your answer. – Volkan Ulukut Sep 29 '14 at 11:19