why cant I return data from $.post (jquery)

前端 未结 6 2463
南旧
南旧 2020-12-19 05:39

I must be making a silly mistake but I cannot return the data I get from a $.post function and store it in a variable, not only that, I cannot return ANYTHING from within th

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 05:55

    You are using the more streamlined .post() method. This is both more finicky to work with (IMHO) and somewhat less powerful than the larger form, $.ajax().

    Personally, I have found the .ajax() method to be preferable because the added structure makes it easier to format. Also, you can do more with .ajax (there are more options, such as turning off asynch which is sometimes very useful when you want to delay processing until the data has been returned).

    Here is a simple example of using the full $.ajax() method. Note the success function at the bottom -- that is where you can use the data sent back from the other PHP file!

提交回复
热议问题