0

I'm building a mobile app and i build a PHP API that renders data from a mysql db and encode it as JSON

i call this api with Jquery ajax to get to display the records from the json output as JSONP and render it in my document in the success function.

so far i get the JSON correctly when i do the request via $.ajax and i can see the data in the Response in my firebug but in the other side the ajax function fires the ERROR not the Success.

i have a demo code in here :jsfidle

this is my $.ajax Call:

$(document).on("pageinit","#myPage", function() {   
    $("#autocomplete").on("listviewbeforefilter", function ( e, data ) {
        var $ul = $( this ),
            $input = $( data.input ),
            value = $input.val(),
            html = "";
            $ul.html( "" );            
            var dataString = 'keyword='+value;
        if (value.length > 2 ) {            
            $.mobile.loading("show");                       
            $.ajax({
                type: "GET",
                url: "http://example.com/search.php",
                dataType: "jsonp",
                jsonpCallback: 'jsonpCallback',               
                cache:true,             
                data: dataString,
                success: function(data) {               
                $.mobile.loading("hide");                                       
                alert(data);                     
                }
            })         
        }
    });
});

if you check the net panel you 'll find it successful and there is data coming.

Kindly Advise. Thanks A lot

2
  • What am I supposed to type so that I don't get No Results for :"bas" returned and instead get this JSON object you speak of? Damnit, I'm not a wizard man! Commented Oct 8, 2013 at 0:04
  • try typing "oyo" or "above" Commented Oct 8, 2013 at 0:06

1 Answer 1

2

Your response is not including the callback jsonpCallback() in the response, the response I'm seeing is simply ({"name": ... })

Sign up to request clarification or add additional context in comments.

1 Comment

i have the callback function now but when i get one set of JSON data its a valid JSON code but when the response comes with more than one record the JSON syntax becomes invalid. my PHP JSON ENCODE is like this : 'echo $_GET[$keyword] . '['.json_encode($row).']';' And this produces an invalid synatax when i get more than one value in the response like this 'Parse error on line 11: ...chord": "Am" }][ { "nam ---------------------^ Expecting 'EOF', '}', ',', ']'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.