simple mootools AJAX call

Posted on 2007-10-21
Last Modified: 2012-08-14
using javascript with mootools,
I want a function that does a synchronous post ajax call with parameters,
and returns the resulting JSON

function simple_ajax(url, params) {
    // url is a standard url
    // params looks something like {'post_param1' : 'value1', 'post_param2' : 'value2'}

    ... what goes here? (probably uses toQueryString)...

    return eval(result)
Question by:xomn
    LVL 82

    Expert Comment

    new ajax(url,{postBody:params, onComplete: handlingFunction, update: 'targetDivId'}).request();
    LVL 82

    Accepted Solution

    Better yet:
    new ajax(url,{postBody:params, onComplete: function(request){processResult(request);}, update: 'targetDivId'}).request();
    function processResult(requestObj)
          //use this if you are returning JSON
          var data="";
    LVL 51

    Expert Comment

    >       eval("data="+result.responseText+";");
    outch, hopefully there is no posibility for an attacker to manipulate this data ...

    evil eval ...
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    The viewer will learn how to dynamically set the form action using jQuery.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now