Error when echo $_GET[“jsoncallback”]

后端 未结 5 1107
挽巷
挽巷 2021-01-29 10:30


        
5条回答
  •  执笔经年
    2021-01-29 10:44

    You don't say where the error is, but presumably it is in JS:

    1. Terminate your statements with a ;
    2. Generate valid JS. You can't just shove a bunch of HTML in a JS function call. You need some sort of JavaScript object. json_encode will generate an Object or an Array. Or you could construct a string but escaping characters with special meaning, replacing new lines, and quoting the value.
    3. Sanity check your $_GET data to make sure it conforms to the syntax of JS function names.

    Oh, I see you have tagged this as JSON-P, in that case:

    Construct a single object with all the data, convert it to JSON with encode_json, then wrap the whole thing with the callback( and );. Don't call the callback multiple times in a while loop.

提交回复
热议问题