More in this section

Forums / General Discussions / JQuery error after upgrading to 4.1

JQuery error after upgrading to 4.1

9 posts, 0 answered
  1. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    20 Apr 2011
    Link to this post
    Hi,

    I have a javascript function that calls a webmethod using ajax calling.
    After upgrading to Q1, the webmethod calling url changes to append "?callback=jQuery151017602539529474603_1303318328937"

    And the ajax call failed and throws the error attached in "Error.png".
    Also the code can be found in "JavascriptSnippet.png"

    Do you have any idea for this issue please?

    Thanks.
  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    20 Apr 2011
    Link to this post
    Hmmm, with that callback appended I would assume it would need to be jsonp?
  3. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    20 Apr 2011
    Link to this post
    Thanks Steve for the reply,
    I tried to change the data type to jsonp, I got an error "Missign 'parameter1' "
    The webmethod can't get the parameters sent.

    Any suggestions please?

    Thanks.
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    20 Apr 2011
    Link to this post
    Yeah I think it;s a little more involved for jsonp

    var callbackurl = getAlfrescoServiceURL() + "&callback=?"; //Get the full URL for the alfresco feed
     
            //set defaultval on param
            if (param == null || param == "")
                param = "none";
     
            //CLEAR
            resetmediaitems();
     
            //initate ajax callback to get the lecture items
            $.getJSON(callbackurl, "param=" + $.trim(param), function (data) {
                //delete the loading panel
                $(".loadingpanel").remove();
     
                if (data.mediaitems.length > 0) {  //Make sure we only loop if there's items
                    createListLayout(data); //Gets a list view of the data
                }
     
                //Create the Pager
                var count = data.mediaitems.length;
                $("#pager").ajaxPager({ startPage: 1, PagesCount: 1, ChangeSiteEvent: PageClick });
     
                firstLoad = false;
            });

    This is a snippit from something else I'm calling with jsonp...so the idea is the return value specifies the function name the javacsript will run (the callbackurl).

    Doc
  5. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    20 Apr 2011
    Link to this post
    Hi Steve,
    I used getJSON function, the webmethod url changed to "http://localhost:53653/Services/WebServices.asmx/AddToFavorities&callback=jQuery15108446318376319131_1303328595466?favorities=185&_=1303328634562"
    and I got "400 bad request error"

    Thanks
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    20 Apr 2011
    Link to this post
    Looks like you have a querystring problem there

    First param should start with a ? then the others are &

    In my sample I already have a couple in the getAlfrescoServiceURL() :o  Sorry about that

    So should be something like

    AddToFavorities?callback=jQuery15108446318376319131_1303328595466&favorities=185&_=1303328634562
    (is the underscore valid as a querystring key?)
  7. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    20 Apr 2011
    Link to this post
    sorry Steve, 

    this is the url of the webmethod "http://localhost:53653/Services/WebServices.asmx/AddToFavorities?callback=jQuery15109481079962976987_1303329897380&favorities=185&_=1303329919010"

    and this is the javascript code "$.getJSON("/Services/WebServices.asmx/AddToFavorities", "favorities=185", function (data) { alert(data) });"
  8. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    21 Apr 2011
    Link to this post
    I am not using cross domain requests, using json not jsonp, so why the "?callback=" is appended to the url?
    and why I got this issue after upgrading to Q1?

    Thanks.
  9. AmrElsayed
    AmrElsayed avatar
    87 posts
    Registered:
    18 Jul 2012
    21 Apr 2011
    Link to this post
    Thanks guys, I resolved the issue.

    It was about an issue in JQuery validation plugin v1.7, it changes the ajax behavior to be jsonp instead of json.
    http://www.victorocastro.com/2011/02/26/jquery-1-5-converting-json-to-jsonp-for-local-requests-what-the-219/

    Thanks.
9 posts, 0 answered